Fixed-Width Integer Types (<cstdint>
/ <stdint.h>
)
These are portable and recommended for predictable behavior.
Type | Size | Signed Range | Unsigned Range |
---|
int8_t | 8 bits | -128 to 127 | — |
uint8_t | 8 bits | — | 0 to 255 |
int16_t | 16 bits | -32,768 to 32,767 | — |
uint16_t | 16 bits | — | 0 to 65,535 |
int32_t | 32 bits | -2,147,483,648 to 2,147,483,647 | — |
uint32_t | 32 bits | — | 0 to 4,294,967,295 |
int64_t | 64 bits | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | — |
uint64_t | 64 bits | — | 0 to 18,446,744,073,709,551,615 |
Standard C++ Integer Types (<limits>
)
Type | Typical Size (LP64) | Signed Range | Unsigned Range |
---|
char | 8 bits | -128 to 127 (if char is signed) | 0 to 255 (if char is unsigned) |
signed char | 8 bits | -128 to 127 | — |
unsigned char | 8 bits | — | 0 to 255 |
short | 16 bits | -32,768 to 32,767 | 0 to 65,535 |
unsigned short | 16 bits | — | 0 to 65,535 |
int | 32 bits | -2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 |
unsigned int | 32 bits | — | 0 to 4,294,967,295 |
long | 64 bits | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 |
unsigned long | 64 bits | — | 0 to 18,446,744,073,709,551,615 |
long long | 64 bits | Same as long | Same as unsigned long |
unsigned long long | 64 bits | — | Same as unsigned long |