1. The arithmetic types are divided into two categories: integer and floating-point. The size of the arithmetic type differs on different machines, and the following table lists the minimum values for the dimensions specified by the C + + standard. It also allows the compiler to give these types a larger size.
A char is the same size as a machine byte.
An int is at least as big as a short;
A long is at least as large as an int;
A long long is at least as large as a long;
The following excerpt from MSDN:
category |
type |
content |
Integer |
char |
char a type is an integer type that typically contains a member of the basic execution character set-by default, this is ASCII in Microsoft C + +. The C + + compiler treats char signed char unsigned char variables of type, and types as different types. char variables of type will be promoted as if int they were types by default signed char , unless the/j compilation option is used. In this case, they are treated as unsigned char types and promoted to int (no symbol extension). |
|
bool |
bool A type is an true integer type that can have or false one of these two values. Its size is not specified. |
|
short |
short int type (or short ) is an integral type that is greater than or equal to the size of the char type but less than or equal to the size of the int type.
short object of type can be declared as signed short or unsigned short . Signed short is short synonymous with. |
|
int |
int Type is an integer type greater than or equal to the size of the short int type but less than or equal to the size of the long type.
int object of type can be declared as signed int or unsigned int . Signed int is int synonymous with. |
|
__int8 , __int16 , __int32 , __int64 ,__int128 |
A fixed-size integer __int``n that n is the size (in bits) of the integer variable. (,,,, __int8 __int16 __int32 __int64 and __int128 are Microsoft-specific keywords.) Not all types are available on all architectures. ) |
|
long |
long The type (or long int ) is an integer type that is greater than or equal to the int size of the type.
long object of type can be declared as signed long or unsigned long . Signed long is long synonymous with. |
|
long long |
is greater than unsigned long .
long long object of type can be declared as signed long long or unsigned long long . Signed long long is long long synonymous with. |
|
wchar_t ,__wchar_t |
wchar_t A variable of type specifies a wide character or multibyte character type. By default, wchar_t this is a native type, but you can use/zc:wchar_t-to make a wchar_t unsigned short typedef. The __wchar_t type is a wchar_t Microsoft-specific synonym for the native type. Use the L prefix before a character or string literal to specify a wide character type. |
Floating point |
float |
float Type is the smallest floating-point type. |
|
double |
double A type is a floating-point type that is greater than or equal to the size of the float type but less than or equal to the long double type. Microsoft private: long double and double the representations are identical. But, long double and double are different types. |
|
long double |
long double type is a double floating-point type greater than or equal to the type. |
Microsoft-Only
The following table lists the amount of storage required for the underlying types in Microsoft C + +.
type |
size |
bool , char , unsigned char , signed char ,__int8 |
1 bytes |
__int16 , short , unsigned short , wchar_t ,__wchar_t |
2 bytes |
float , __int32 , int , unsigned int , long ,unsigned long |
4 bytes |
double , __int64 , long double ,long long |
8 bytes |
__int128 |
16 bytes |
The ranges specified in the following table contain both a start value and an end value.
type name |
bytes |
Other Name |
range of Values |
Int |
4 |
Signed |
–2,147,483,648 to 2,147,483,647 |
unsigned int |
4 |
Unsigned |
0 to 4,294,967,295 |
__int8 |
1 |
Char |
–128 to 127 |
unsigned __int8 |
1 |
unsigned char |
0 to 255 |
__int16 |
2 |
short, short int, signed short int |
–32,768 to 32,767 |
unsigned __int16 |
2 |
unsigned short, unsigned short int |
0 to 65,535 |
__int32 |
4 |
Signed, signed int, int |
–2,147,483,648 to 2,147,483,647 |
unsigned __int32 |
4 |
unsigned, unsigned int |
0 to 4,294,967,295 |
__int64 |
8 |
Long long, signed long long |
–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
unsigned __int64 |
8 |
unsigned long long |
0 to 18,446,744,073,709,551,615 |
bool |
1 |
No |
False or True |
Char |
1 |
No |
128 to 127 (default) 0 to 255 (when compiling with/j) |
Signed Char |
1 |
No |
–128 to 127 |
unsigned char |
1 |
No |
0 to 255 |
Short |
2 |
short int, signed short int |
–32,768 to 32,767 |
unsigned short |
2 |
unsigned short int |
0 to 65,535 |
Long |
4 |
Long int, signed long int |
–2,147,483,648 to 2,147,483,647 |
unsigned long |
4 |
unsigned long int |
0 to 4,294,967,295 |
Long Long |
8 |
None (equivalent to __int64) |
–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
unsigned long long |
8 |
None (equivalent to unsigned __int64) |
0 to 18,446,744,073,709,551,615 |
Enum |
Varies |
No |
See remarks later in this article |
Float |
4 |
No |
3.4E +/-38 (7-digit) |
Double |
8 |
No |
1.7E +/-308 (15-digit) |
Long double |
Same as Double |
No |
Same as Double |
wchar_t |
2 |
__wchar_t |
0 to 65,535 |
2. When we assign an unsigned type to a value that is outside its range, the result is the remainder of the initial value that represents the total number of numeric values for the unsigned type. When we assign a symbol type to a value that exceeds the range it represents, the result is undefined.
3. When an arithmetic expression has both an unsigned number and an int value, the int value is converted to the unsigned number.
4. Integers starting with 0 represent octal, representing hexadecimal numbers beginning with 0x 0X.
5. Specify the type of literal value.
C + + Primer notes-Basic built-in types