Void type
- void - type with an empty set of values. It is an incomplete type that cannot be completed (consequently, objects of type
voidare disallowed). There are no arrays of
void, nor references to
void. However, pointers to
voidand functions returning type
void(procedures in other languages) are permitted.
Defined in header
typedef decltype(nullptr) nullptr_t;
 Boolean type
- bool - type, capable of holding one of the two values: true or false. The value of sizeof(bool) is implementation defined and might differ from 1.
 Integer types
- int - basic integer type. The keyword
intmay be omitted if any of the modifiers listed below are used. If no length modifiers are present, it's guaranteed to have a width of at least 16 bits. However, on 32/64 bit systems it is almost exclusively guaranteed to have width of at least 32 bits (see below).
Modifies the integer type. Can be mixed in any order. Only one of each group can be present in type name.
- signed - target type will have signed representation (this is the default if omitted)
- unsigned - target type will have unsigned representation
- short - target type will be optimized for space and will have width of at least 16 bits.
- long - target type will have width of at least 32 bits.
Note: as with all type specifiers, any order is permitted: unsigned long long int and long int unsigned long name the same type.
The following table summarizes all available integer types and their properties:
|Type specifier||Equivalent type||Width in bits by data model|
|short int|| at least
signed short int
|unsigned short int|
unsigned short int
|int|| at least
|long int|| at least
signed long int
|unsigned long int|
unsigned long int
| long long int
| at least
long long int
signed long long
signed long long int
unsigned long long
| unsigned long long int |
unsigned long long int
std::size_t is the unsigned integer type of the result of the sizeof operator as well as the sizeof... operator and the alignof operator (since C++11).
See also Fixed width integer types. (since C++11)
 Data models
The choices made by each implementation about the sizes of the fundamental types are collectively known as data model. Four data models found wide acceptance:
32 bit systems:
- LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit)
- Win16 API
- ILP32 or 4/4/4 (int, long, and pointer are 32-bit);
- Win32 API
- Unix and Unix-like systems (Linux, Mac OS X)
64 bit systems:
- LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit)
- Win64 API
- LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit)
- Unix and Unix-like systems (Linux, Mac OS X)
Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. Unicos on Cray).
 Character types
- signed char - type for signed character representation.
- unsigned char - type for unsigned character representation. Also used to inspect object representations (raw memory).
- char - type for character representation which can be most efficiently processed on the target system (has the same representation and alignment as either signed char or unsigned char, but is always a distinct type). Multibyte characters strings use this type to represent code units. The character types are large enough to represent any UTF-8 eight-bit code unit (since C++14). The signedness of char depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed.
- wchar_t - type for wide character representation (see wide strings). Required to be large enough to represent any supported character code point (32 bits on systems that support Unicode. A notable exception is Windows, where wchar_t is 16 bits and holds UTF-16 code units) It has the same size, signedness, and alignment as one of the integer types, but is a distinct type.
Besides the minimal bit counts, the C++ Standard guarantees that
- 1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long).
Note: this allows the extreme case in which bytes are sized 64 bits, all types (including char) are 64 bits wide, and sizeof returns 1 for every type.
 Floating point types
- float - single precision floating point type. Usually IEEE-754 32 bit floating point type
- double - double precision floating point type. Usually IEEE-754 64 bit floating point type
- long double - extended precision floating point type. Does not necessarily map to types mandated by IEEE-754. Usually 80-bit x87 floating point type on x86 and x86-64 architectures.
Floating-point types may support special values:
- infinity (positive and negative), see INFINITY
- the negative zero, -0.0. It compares equal to the positive zero, but is meaningful in some arithmetic operations, e.g. 1.0/0.0 == INFINITY, but 1.0/-0.0 == -INFINITY), and for some mathematical functions, e.g. sqrt(std::complex)
- not-a-number (NaN), which does not compare equal with anything (including itself). Multiple bit patterns represent NaNs, see std::nan, NAN. Note that C++ takes no special notice of signalling NaNs other than detecting their support by std::numeric_limits::has_signaling_NaN, and treats all NaNs as quiet.
Real floating-point numbers may be used with arithmetic operators + - / * and various mathematical functions from cmath. Both built-in operators and library functions may raise floating-point exceptions and set errno as described in math_errhandling
Floating-point expressions may have greater range and precision than indicated by their types, see FLT_EVAL_METHOD. Floating-point expressions may also be contracted, that is, calculated as if all intermediate values have infinite range and precision, see #pragma STDC FP_CONTRACT.
Some operations on floating-point numbers are affected by and modify the state of the floating-point environment (most notably, the rounding direction)
Implicit conversions are defined between real floating types and integer types.
 Range of values
The following table provides a reference for the limits of common numeric representations.
Prior to C++20, the C++ Standard allowed any signed integer representation, and the minimum guaranteed range of N-bit signed integers was from -(2N-1
-1) to +2N-1
-1 (e.g. -127 to 127 for a signed 8-bit type), which corresponds to the limits of one's complement or sign-and-magnitude.
However, all C++ compilers use two's complement representation, and as of C++20, it is the only representation allowed by the standard, with the guaranteed range from -2N-1
-1 (e.g. -128 to 127 for a signed 8-bit type).
|Type||Size in bits||Format||Value range|
|character||8||signed||-128 to 127|
|unsigned||0 to 255|
|16||unsigned||0 to 65535|
|32||unsigned||0 to 1114111 (0x10ffff)|
|integer||16||signed||± 3.27 · 104||-32768 to 32767|
|unsigned||0 to 6.55 · 104||0 to 65535|
|32||signed||± 2.14 · 109||-2,147,483,648 to 2,147,483,647|
|unsigned||0 to 4.29 · 109||0 to 4,294,967,295|
|64||signed||± 9.22 · 1018||-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807|
|unsigned||0 to 1.84 · 1019||0 to 18,446,744,073,709,551,615|
 See also
- the C++ type system overview
- const-volatility (cv) specifiers and qualifiers
- storage duration specifiers
C documentation for arithmetic types