Built-in types (C++)
Built-in types (also called fundamental types) are specified by the C++ language standard and are built into the compiler. Built-in types aren't defined in any header file. Built-in types are divided into three main categories: integral, floating-point, and void. Integral types represent whole numbers. Floating-point types can specify values that may have fractional parts. Most built-in types are treated as distinct types by the compiler. However, some types are synonyms, or treated as equivalent types by the compiler.
void type describes an empty set of values. No variable of type
void can be specified. The
void type is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data. Any expression can be explicitly converted or cast to type
void. However, such expressions are restricted to the following uses:
An expression statement. (For more information, see Expressions.)
The left operand of the comma operator. (For more information, see Comma Operator.)
The second or third operand of the conditional operator (
? :). (For more information, see Expressions with the Conditional Operator.)
nullptr is a null-pointer constant of type
std::nullptr_t, which is convertible to any raw pointer type. For more information, see
bool type can have values
false. The size of the
bool type is implementation-specific. See Sizes of built-in types for Microsoft-specific implementation details.
char type is a character representation type that efficiently encodes members of the basic execution character set. The C++ compiler treats variables of type
signed char, and
unsigned char as having different types.
Microsoft-specific: Variables of type
char are promoted to
int as if from type
signed char by default, unless the
/J compilation option is used. In this case, they're treated as type
unsigned char and are promoted to
int without sign extension.
A variable of type
wchar_t is a wide-character or multibyte character type. Use the
L prefix before a character or string literal to specify the wide-character type.
Microsoft-specific: By default,
wchar_t is a native type, but you can use
/Zc:wchar_t- to make
wchar_t a typedef for
unsigned short. The
__wchar_t type is a Microsoft-specific synonym for the native
char8_t type is used for UTF-8 character representation. It has the same representation as
unsigned char, but is treated as a distinct type by the compiler. The
char8_t type is new in C++20. Microsoft-specific: use of
char8_t requires the
/std:c++20 compiler option or later (such as
char16_t type is used for UTF-16 character representation. It must be large enough to represent any UTF-16 code unit. It's treated as a distinct type by the compiler.
char32_t type is used for UTF-32 character representation. It must be large enough to represent any UTF-32 code unit. It's treated as a distinct type by the compiler.
Floating-point types use an IEEE-754 representation to provide an approximation of fractional values over a wide range of magnitudes. The following table lists the floating-point types in C++ and the comparative restrictions on floating-point type sizes. These restrictions are mandated by the C++ standard and are independent of the Microsoft implementation. The absolute size of built-in floating-point types isn't specified in the standard.
Microsoft-specific: The representation of
long double and
double is identical. However,
long double and
double are treated as distinct types by the compiler. The Microsoft C++ compiler uses the 4- and 8-byte IEEE-754 floating-point representations. For more information, see IEEE floating-point representation.
int type is the default basic integer type. It can represent all of the whole numbers over an implementation-specific range.
A signed integer representation is one that can hold both positive and negative values. It's used by default, or when the
signed modifier keyword is present. The
unsigned modifier keyword specifies an unsigned representation that can only hold non-negative values.
A size modifier specifies the width in bits of the integer representation used. The language supports
long long modifiers. A
short type must be at least 16 bits wide. A
long type must be at least 32 bits wide. A
long long type must be at least 64 bits wide. The standard specifies a size relationship between the integral types:
1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
An implementation must maintain both the minimum size requirements and the size relationship for each type. However, the actual sizes can and do vary between implementations. See Sizes of built-in types for Microsoft-specific implementation details.
int keyword may be omitted when
unsigned, or size modifiers are specified. The modifiers and
int type, if present, may appear in any order. For example,
short unsigned and
unsigned int short refer to the same type.
Integer type synonyms
The following groups of types are considered synonyms by the compiler:
signed short int
unsigned short int
signed long int
unsigned long int
long long int,
signed long long,
signed long long int
unsigned long long,
unsigned long long int
Microsoft-specific integer types include the specific-width
__int64 types. These types may use the
unsigned modifiers. The
__int8 data type is synonymous with type
__int16 is synonymous with type
__int32 is synonymous with type
__int64 is synonymous with type
Sizes of built-in types
Most built-in types have implementation-defined sizes. The following table lists the amount of storage required for built-in types in Microsoft C++. In particular,
long is 4 bytes even on 64-bit operating systems.
See Data type ranges for a summary of the range of values of each type.
For more information about type conversion, see Standard conversions.
Submit and view feedback for