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,647unsigned int
4 unsigned 0 到 4,294,967,295_int8
1 char –128 到 127unsigned _int8
1 unsigned char 0 到 255__int16
2 short、short int、signed short int –32,768 到 32,767unsigned __int16
2 unsigned short、unsigned short int 0 到 65,535__int32
4 signed、signed int、int –2,147,483,648 到 2,147,483,647unsigned __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,807unsigned __int64
8 unsigned long long 0 到 18,446,744,073,709,551,615bool
1 無 false 或 truechar
1 無-128 到 127(默認)
/J">0 到 255(當使用/J編譯時)
signed char
1 無 –128 到 127unsigned char
1 無 0 到 255short
2 short int、signed short int –32,768 到 32,767unsigned short
2 unsigned short int 0 到 65,535long
4 long int、signed long int –2,147,483,648 到 2,147,483,647unsigned long
4 0 到 4,294,967,295long long
8 無(與 __int64 等效) –9,223,372,036,854,775,808 到 9,223,372,036,854,775,807unsigned long long
8 無(與無符號的 __int64 等效) 0 到 18,446,744,073,709,551,615enum
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的大小。