🪅Data Types
Integer types:
char
: 1 byteshort
: 2 bytesint
: 4 bytes (can be 2 bytes on some 16-bit systems)long
: 4 bytes on 32-bit systems, 8 bytes on 64-bit systemslong long
: 8 bytes
Unsigned integer types:
unsigned char
: 1 byteunsigned short
: 2 bytesunsigned int
: 4 bytesunsigned long
: 4 bytes (32-bit) or 8 bytes (64-bit)unsigned long long
: 8 bytes
Floating-point types:
float
: 4 bytesdouble
: 8 byteslong double
: 12 or 16 bytes (compiler dependent)
Boolean type:
bool
: 1 byte
Void type:
void
: no size (used to indicate no value)
Wide character type:
wchar_t
: 2 or 4 bytes (compiler dependent)
Character types (C++11 and later):
char16_t
: 2 byteschar32_t
: 4 bytes
Fixed-width integer types (C++11 and later):
int8_t
,uint8_t
: 1 byteint16_t
,uint16_t
: 2 bytesint32_t
,uint32_t
: 4 bytesint64_t
,uint64_t
: 8 bytes
To get the exact size of a type on your specific system and compiler, you can use the sizeof
operator:
Example showcasing overflow, causing wrap:
Run it here.
Last updated