(See also type for type system overview and the list of type-related utilities that are provided by the C++ library)
The following types are collectively called fundamental types :
Modifies the basic integer type. Can be mixed in any order. Only one of each group can be present in type name.
Note: as with all type specifiers, any order is permitted: unsigned long long int and long int unsigned long name the same type.
[edit] PropertiesThe following table summarizes all available standard integer types and their properties in various common data models:
Type specifier Equivalent type Width in bits by data model C++ standard LP32 ILP32 LLP64 LP64signed char
signed char at leastunsigned char
unsigned charshort
short int at leastshort int
signed short
signed short int
unsigned short
unsigned short intunsigned short int
int
int at leastsigned
signed int
unsigned
unsigned intunsigned int
long
long int at leastlong int
signed long
signed long int
unsigned long
unsigned long intunsigned long int
long long
long long intlong long int
signed long long
signed long long int
unsigned long long
unsigned long long intunsigned long long int
Note: integer arithmetic is defined differently for the signed and unsigned integer types. See arithmetic operators, in particular integer overflows.
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).
The extended integer types are implementation-defined. Note that fixed width integer types are typically aliases of the standard integer types.
(since C++11) [edit] Boolean typetrue
or false
. The value of sizeof(bool) is implementation defined and might differ from 1.
Character types are integer types used for a character representation.
[
â0â,
255]
, converting the value to char and then back to unsigned char produces the original value.(since C++11) 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.
Besides the minimal bit counts, the C++ Standard guarantees that
≤
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.
The following three types and their cv-qualified versions are collectively called standard floating-point types.
Floating-point types may support special values:
Floating-point numbers may be used with arithmetic operators +, -, /, and * as well as 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. Standard C++ does not restrict the accuracy of floating-point operations.
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 floating types and integer types.
See limits of floating-point types and std::numeric_limits for additional details, limits, and properties of the floating-point types.
[edit] Range of valuesThe 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 \(\scriptsize -(2^{N-1}-1)\)-(2N-1
-1) to \(\scriptsize +2^{N-1}-1\)+2N-1
-1 (e.g. â127 to 127 for a signed 8-bit type), which corresponds to the limits of ones' 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 \(\scriptsize -2^{N-1}\)-2N-1
to \(\scriptsize +2^{N-1}-1\)+2N-1
-1 (e.g. â128 to 127 for a signed 8-bit type).
8-bit ones' complement and sign-and-magnitude representations for char have been disallowed since C++11 (via the resolution of CWG issue 1759), because a UTF-8 code unit of value 0x80 used in a UTF-8 string literal must be storable in a char type object.
The range for a floating-point type T
is defined as follows:
T
through the most positive finite floating-point number representable in T
.T
, the range of T
is extended to all negative real numbers.T
, the range of T
is extended to all positive real numbers.Since negative and positive infinity are representable in ISO/IEC/IEEE 60559 formats, all real numbers lie within the range of representable values of a floating-point type adhering to ISO/IEC/IEEE 60559.
Type Size in bits Format Value range Approximate Exact character 8 signed â128 to 127 unsigned 0 to 255 16 UTF-16 0 to 65535 32 UTF-32 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 binaryNote: actual (as opposed to guaranteed minimal) limits on the values representable by these types are available in C numeric limits interface and std::numeric_limits.
[edit] Data modelsThe 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:
64 bit systems:
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).
[edit] Notes [edit] Keywordsvoid, bool, true, false, char, char8_t, char16_t, char32_t, wchar_t, int, short, long, signed, unsigned, float, double
[edit] Defect reportsThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior CWG 238 C++98 the constraints placed on a floating-point implementation was unspecified specified asRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4