In C++ development, integer variables can be decimal (base 10
), octal (base 8
) or hexadecimal (base 16
). In addition to int
, short int
, long int
, and long long int
, there are fixed width integer types. Fixed-width integers are defined types with a fixed number of bits. In this post we will list them.
What are fixed width integer types in modern C++?
In addition to standard types in C++, there are fixed-width integers which are defined types in header <cstdint>
with a fixed number of bits. Fixed-width integers are called as intN_t
or intX_t
integers where N or X represents number of bits reserved for that type. That means, these integer types guarantee a specific size in bits, and can be portable to any other platform. Mostly we use decimal variables which are in ranges from 0
to 4,294,967,295
but there are many different types of integers that allows developers use the memory wisely.
What are fixed width signed integer types in modern C++?
Fixed-width integers which are defined types in header <cstdint>
, and these can be listed as below,
Here are signed with integer types:
Fixed Width Integer Types | Description |
int8_t | 8 bits signed integer type |
int16_t | 16 bits signed integer type |
int32_t | 32 bits signed integer type |
int64_t | 64 bits signed integer type |
Here are signed integer types ‘fastest form’:
Fixed Width Integer Types | Description |
int_fast8_t | 8 bits fast signed integer type |
int_fast16_t | 16 bits fast signed integer type |
int_fast32_t | 32 bits fast signed integer type |
int_fast64_t | 64 bits fast signed integer type |
Here are signed with integer types in ‘smallest form’:
Fixed Width Integer Types | Description |
int_least8_t | 8 bits smallest signed integer type |
int_least16_t | 16 bits smallest signed integer type |
int_least32_t | 32 bits smallest signed integer type |
int_least64_t | 64 bits smallest signed integer type |
and there is also maximum-width signed integer type:
Fixed Width Integer Types | Description |
intmax_t | integer type that has maximum-width |
and a signed integer type that holds pointer:
Fixed Width Integer Types | Description |
intptr_t | signed integer type that holds pointer |
What are fixed width unsigned integer types in modern C++
If you are sure that your integer variable is a zero or a positive number, you can use an unsigned version that doubles the highest integer number which can be used in that variable.
Here are unsigned with integer types in general form:
Fixed Width Integer Types | Description |
uint8_t | 8 bits unsigned integer type |
uint16_t | 16 bits unsigned integer type |
uint32_t | 32 bits unsigned integer type |
uint64_t | 64 bits unsigned integer type |
Here are unsigned with integer types in fastest form:
Fixed Width Integer Types | Description |
uint_fast8_t | 8 bits fast unsigned integer type |
uint_fast16_t | 16 bits fast unsigned integer type |
uint_fast32_t | 32 bits fast unsigned integer type |
uint_fast64_t | 64 bits fast unsigned integer type |
Here are signed with integer types in smallest form:
Fixed Width Integer Types | Description |
uint_least8_t | 8 bits smallest unsigned integer type |
uint_least16_t | 16 bits smallest unsigned integer type |
uint_least32_t | 32 bits smallest unsigned integer type |
uint_least64_t | 64 bits smallest unsigned integer type |
and there is also maximum-width unsigned integer type:
Fixed Width Integer Types | Description |
uintmax_t | integer type that has maximum-width |
and unsigned integer type that holds pointer:
Fixed Width Integer Types | Description |
uintptr_t | unsigned integer type that holds pointer |
If you are looking more about Integer constants there are more details about them, https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Integer_Constants
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition