C++中有很多基本的数据类型,我们在使用过程中需要根据所需要存储数据的范围的不同而选择恰当的数据类型。
Visual C++ 32 位和 64 位编译器可识别本文后面的表中的类型。
int (unsignedint)">int(unsignedint)
__int8 (unsigned__int8)">__int8(unsigned__int8)
__int16 (unsigned__int16)">__int16(unsigned__int16)
__int32 (unsigned__int32)">__int32(unsigned__int32)
__int64 (unsigned__int64)">__int64(unsigned__int64)
short (unsignedshort)">short(unsignedshort)
long (unsignedlong)">long(unsignedlong)
longlong (unsignedlonglong)">longlong(unsignedlonglong)
__), a data type is non-standard.">如果其名称以两个下划线 (__) 开始,则数据类型是非标准的。
下表中指定的范围均包含起始值和结束值。
类型名称 字节 其他名称 值的范围
int 4 signed –2,147,483,648 到 2,147,483,647
unsigned int 4 unsigned 0 到 4,294,967,295
_int8 1 char –128 到 127
unsigned _int8 1 unsigned char 0 到 255
__int16 2 short、short int、signed short int –32,768 到 32,767
unsigned __int16 2 unsigned short、unsigned short int 0 到 65,535
__int32 4 signed、signed int、int –2,147,483,648 到 2,147,483,647
unsigned __int32 4 unsigned、unsigned int 0 到 4,294,967,295
__int64 8 long long、signed long long –9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
unsigned __int64 8 unsigned long long 0 到 18,446,744,073,709,551,615
bool 1 无 false 或 true
char 1 无
-128 到 127(默认)
/J">0 到 255(当使用/J编译时)
signed char 1 无 –128 到 127
unsigned char 1 无 0 到 255
short 2 short int、signed short int –32,768 到 32,767
unsigned short 2 unsigned short int 0 到 65,535
long 4 long int、signed long int –2,147,483,648 到 2,147,483,647
unsigned long 4 0 到 4,294,967,295
long long 8 无(与 __int64 等效) –9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
unsigned long long 8 无(与无符号的 __int64 等效) 0 到 18,446,744,073,709,551,615
enum varies 无 用户自己定义的类型,其中包含一组称为枚举器的命名的整型常数。
浮动 4 无 3.4E +/- 38(7 位数)
double 8 无 1.7E +/- 308(15 位数)
long double 与double相同 无 与 double 相同
wchar_t 2 __wchar_t 0 到 65,535
__wchar_t designates either a wide-character type or multibyte-character type.">根据使用方式,__wchar_t的变量指定宽字符类型或多字节字符类型。L prefix before a character or string constant to designate the wide-character-type constant.">在字符或字符串常量前使用L前缀以指定宽字符类型常量。
signed and unsigned are modifiers that you can use with any integral type except bool.">signed和unsigned是可用于任何整型(bool除外)的修饰符。char, signed char, and unsigned char are three distinct types for the purposes of mechanisms like overloading and templates.">请注意,对于重载和模板等机制而言,char、signed char和unsigned char是三种不同的类型。
int and unsignedint types have a size of four bytes.">int和unsignedint类型具有四个字节的大小。int because the language standard allows this to be implementation-specific.">但是,由于语言标准允许可移植代码特定于实现,因此该代码不应依赖于int的大小。
|