The fundamental data types in C++ are the basic building blocks for creating other data types. There are five basic classifications that form the foundation of the fundamental types: characters, integers, floating-point numbers, booleans, and the void type.
The character type has two basic variants: one of ACSII characters and one for Unicode characters. The char type is used to store 8 bit characters according to the specification in the ASCII table. The wchar_t type is used to store 16 bit characters according to the Unicode specification for UTF 16. The actual values stored in these data types are integers whose values are seldom used directly. However, due to the legacy usage of C/C++, there are three specifications for the char type: char, signed char, and unsigned char
The integer type has three distinct sizes: 16 bit, 32 bit and 64 bit. You could also add in the char type as an 8 bit variant. Each different size can store a corresponding range of integer values and each has a signed and unsigned variant. Many of these have multiple names that can be used to specify it.
The floating point number type has two distinct sizes: 32 bit and 64 bit. The 32 bit variant is specified by the name float and the 64 bit number is specified by the name double. The double has uses twice the memory to give a range of values and greater precision. As memory in computers has grown, the float type has fallen out of usage in numerical programming, and virtually everyone uses the double type now.
The only Boolean type is the bool data type. This is used to represent the two logical values true and false.
There is one Void type called void, it is not really a data type at all. It is used to specify that no type is used. Otherwise, it can be used as a pointer type to indicate that the type is unknown.
Category | Type | Range | Size * |
Character | char | [-128, 127] | 1 byte |
signed char | [-128, 127] | 1 byte | |
unsigned char | [0,255] | 1 byte | |
wchar_t | [0, 65535] | 2 bytes | |
Integer | |||
short | [-32768, 32767] | 2 bytes | |
short int | [-32768, 32767] | 2 bytes | |
signed short int | [-32768, 32767] | 2 bytes | |
signed | [-2147483648, 2147483647] | 4 bytes | |
signed int | [-2147483648, 2147483647] | 4 bytes | |
int | [-2147483648, 2147483647] | 4 bytes | |
long | [-2147483648, 2147483647] | 4 bytes | |
long int | [-2147483648, 2147483647] | 4 bytes | |
signed long int | [-2147483648, 2147483647] | 4 bytes | |
long long | [-9223372036854775808, 9223372036854775807] | 8 bytes | |
unsigned short | [0, 65535] | 2 bytes | |
unsigned short int | [0, 65535] | 2 bytes | |
unsigned | [0, 4294967295] | 4 bytes | |
unsigned int | [0, 4294967295] | 4 bytes | |
unsigned long | [0, 4294967295] | 4 bytes | |
unsigned long int | [0, 4294967295] | 4 bytes | |
unsigned long long | [0, 18446744073709551615] | 8 bytes | |
Floating Point | |||
float | [-3.4*10^38, 3.4*10^38] (7 decimal place accuracy) | 4 bytes | |
double | [-1.7*10^308, 1.7*10^308] (15 decimal place accuracy) | 8 bytes | |
long double | [-1.7*10^308, 1.7*10^308] (15 decimal place accuracy) | 8 bytes | |
Boolean | bool | {true, false} | 1 byte |
Void | void | | |
Note: The sizes above are Visual C++-specific. Other compilers may vary, but the relationships in the Guaranteed Size Relationships section always hold.
1 = sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) | |
1 <= sizeof(bool) <= sizeof(long) | |
sizeof(char) <= sizeof(wchar_t) <= sizeof(long) | |
sizeof(float) <= sizeof(double) <= sizeof(long double) | |
sizeof(N) = sizeof(signed N) = sizeof(unsigned N) | |
© 20072025 XoaX.net LLC. All rights reserved.