数据类型总结 (C++)
数据类型总结 (C++)
作用 | C++ | 大小 | 取值范围 | 后缀 |
字符 | char | 1 | -128~127 | |
字符(无符号) | unsigned char | 1 | 0~255 | |
宽字符 | wchar_t | 2 | ||
宽字符(无符号) | unsigned wchar_t | 2 | ||
逻辑值 | bool | 1 | true,false | |
短整数 | short | 2 |
-32,768 .. 32,767 |
|
短整数(无符号) | unsigned short | 2 | 0~65535(2的16次方) | |
整型 | int | 4 |
-2,147,483,648 .. 2,147,483,647 |
|
整型(无符号) | unsigned int | 4 |
0 .. 4,294,967,295 |
|
长整型 | long | 8 |
-9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807 |
L (最好用大写,因为小写l容易与1混淆) |
长整型(无符号) | unsigned long | 8 |
0 .. 18,446,744,073,709,551,615 |
|
单精度实数 | float | 4 |
-3.402823e38 .. 3.402823e38 |
|
双精度实数 | double | 8 |
-1.79769313486232e308 .. 1.79769313486232e308 |
d |
长双精度实数 | long double | 10 |
-79228162514264337593543950335 .. 79228162514264337593543950335 |
m |
字符串 | string | |||
对象 |
- C++中,使用typedef关键字 : typedef short Age;