C++ Standard Library C++ STL Library

C++ - <cstdint> (stdint.h)



The C++ <cstdint> header defines a set of integral type, along with macros specifying their limits and macro functions to create values of these types.

Note: The library <cstdint> was a part of C++11, the second major version of C++ and the most important update since C++98.

C++ <cstdint> Types

The following are typedefs of fundamental integral types or extended integral types.

Signed TypesUnsigned TypesDescription
int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
Integer type with width of exactly 8, 16, 32 and 64 bits respectively.
With no padding bits.
For signed type, using 2's complement for negative values.
int_least8_t
int_least16_t
int_least32_t
int_least64_t
uint_least8_t
uint_least16_t
uint_least32_t
uint_least64_t
Smallest integer type with width of at least 8, 16, 32 and 64 bits respectively.
int_fast8_t
int_fast16_t
int_fast32_t
int_fast64_t
uint_fast8_t
uint_fast16_t
uint_fast32_t
uint_fast64_t
Fastest integer type with width of at least 8, 16, 32 and 64 bits respectively.
intmax_t uintmax_t Integer type with the maximum width supported.
intptr_t uintptr_t Integer type capable of holding a pointer.

C++ <cstdint> Macros

The below mentioned macros are implementation-specific and defined with the #define directive. The table below shows the different macros in <cstdint> header and their minimal or maximal values in all implementations.

Signed integers : minimum value

MacrosDescriptionValue
INT8_MINMinimum value of an object of type int8_t Exactly -27
INT16_MINMinimum value of an object of type int16_t Exactly -215
INT32_MINMinimum value of an object of type int32_t Exactly -231
INT64_MINMinimum value of an object of type int64_t Exactly -263
INT_LEAST8_MINMinimum value of an object of type int_least8_t -(27-1), or lower
INT_LEAST16_MINMinimum value of an object of type int_least16_t -(215-1), or lower
INT_LEAST32_MINMinimum value of an object of type int_least32_t -(231-1), or lower
INT_LEAST64_MINMinimum value of an object of type int_least64_t -(263-1), or lower
INT_FAST8_MINMinimum value of an object of type int_fast8_t -(27-1), or lower
INT_FAST16_MINMinimum value of an object of type int_fast16_t -(215-1), or lower
INT_FAST32_MINMinimum value of an object of type int_fast32_t -(231-1), or lower
INT_FAST64_MINMinimum value of an object of type int_fast64_t -(263-1), or lower
INTPTR_MINMinimum value of an object of type intptr_t -(215-1), or lower
INTMAX_MINMinimum value of an object of type intmax_t -(263-1), or lower

Signed integers : maximum value

MacrosDescriptionValue
INT8_MAXMaximum value of an object of type int8_t Exactly (27-1)
INT16_MAXMaximum value of an object of type int16_t Exactly (215-1)
INT32_MAXMaximum value of an object of type int32_t Exactly (231-1)
INT64_MAXMaximum value of an object of type int64_t Exactly (263-1)
INT_LEAST8_MAXMaximum value of an object of type int_least8_t (27-1), or higher
INT_LEAST16_MAXMaximum value of an object of type int_least16_t (215-1), or higher
INT_LEAST32_MAXMaximum value of an object of type int_least32_t (231-1), or higher
INT_LEAST64_MAXMaximum value of an object of type int_least64_t (263-1), or higher
INT_FAST8_MAXMaximum value of an object of type int_fast8_t (27-1), or higher
INT_FAST16_MAXMaximum value of an object of type int_fast16_t (215-1), or higher
INT_FAST32_MAXMaximum value of an object of type int_fast32_t (231-1), or higher
INT_FAST64_MAXMaximum value of an object of type int_fast64_t (263-1), or higher
INTPTR_MAXMaximum value of an object of type intptr_t (215-1), or higher
INTMAX_MAXMaximum value of an object of type intmax_t (263-1), or higher

Unsigned integers : maximum value

MacrosDescriptionValue
UINT8_MAXMaximum value of an object of type uint8_t Exactly (28-1)
UINT16_MAXMaximum value of an object of type uint16_t Exactly (216-1)
UINT32_MAXMaximum value of an object of type uint32_t Exactly (232-1)
UINT64_MAXMaximum value of an object of type uint64_t Exactly (264-1)
UINT_LEAST8_MAXMaximum value of an object of type uint_least8_t (28-1), or higher
UINT_LEAST16_MAXMaximum value of an object of type uint_least16_t (216-1), or higher
UINT_LEAST32_MAXMaximum value of an object of type uint_least32_t (232-1), or higher
UINT_LEAST64_MAXMaximum value of an object of type uint_least64_t (264-1), or higher
UINT_FAST8_MAXMaximum value of an object of type uint_fast8_t (28-1), or higher
UINT_FAST16_MAXMaximum value of an object of type uint_fast16_t (216-1), or higher
UINT_FAST32_MAXMaximum value of an object of type uint_fast32_t (232-1), or higher
UINT_FAST64_MAXMaximum value of an object of type uint_fast64_t (264-1), or higher
UINTPTR_MAXMaximum value of an object of type uintptr_t (216-1), or higher
UINTMAX_MAXMaximum value of an object of type uintmax_t (264-1), or higher

Limits of other types

MacrosDescriptionValue
SIZE_MAX (C++11)Maximum value of an object of type size_t(264-1), or higher
PTRDIFF_MIN (C++11)Minimum value of an object of type ptrdiff_t-(216-1), or lower
PTRDIFF_MAX (C++11)Maximum value of an object of type ptrdiff_t(216-1), or higher
SIG_ATOMIC_MIN (C++11)Minimum value of an object of type sig_atomic_tIf sig_atomic_t is signed: -127, or lower
If sig_atomic_t is unsigned: 0
SIG_ATOMIC_MAX (C++11)Maximum value of an object of type sig_atomic_tIf sig_atomic_t is signed: 127, or higher
If sig_atomic_t is unsigned: 255, or higher
WCHAR_MIN (C++11)Minimum value of an object of wchar_t typeIf wchar_t is signed: -127, or lower
If wchar_t is unsigned: 0
WCHAR_MAX (C++11)Maximum value of an object of wchar_t typeIf wchar_t is signed: 127, or higher
If wchar_t is unsigned: 255, or higher
WINT_MIN (C++11)Minimum value of an object of wint_t typeIf wint_t is signed: -32767, or lower
If wint_t is unsigned: 0
WINT_MAX (C++11)Maximum value of an object of wint_t typeIf wint_t is signed: 32767, or higher
If wint_t is unsigned: 65535, or higher

Function-like macros

MacrosDescription
INT8_Cexpands to a value of type int_least8_t
INT16_Cexpands to a value of type int_least16_t
INT32_Cexpands to a value of type int_least32_t
INT64_Cexpands to a value of type int_least64_t
UINT8_Cexpands to a value of type uint_least8_t
UINT16_Cexpands to a value of type uint_least16_t
UINT32_Cexpands to a value of type uint_least32_t
UINT64_Cexpands to a value of type uint_least64_t
INTMAX_Cexpands to a value of type intmax_t
UINTMAX_Cexpands to a value of type uintmax_t

Example:

The example below describes the working of macros constant of C++ <cstdint> library.

#include <iostream>
#include <cstdint>
using namespace std;

int main (){
  //using int_least16_t type
  int_least16_t x = 10;

  //displaying maximum and minimum value
  cout<<"INT16_MIN: "<<INT16_MIN<<"\n";
  cout<<"INT16_MAX: "<<INT16_MAX<<"\n"; 
  cout<<"UINT16_MAX: "<<UINT16_MAX<<"\n"; 
  cout<<"INT_LEAST32_MIN: "<<INT_LEAST32_MIN<<"\n";
  cout<<"INT_LEAST32_MAX: "<<INT_LEAST32_MAX<<"\n";
  cout<<"UINT_LEAST32_MAX: "<<UINT_LEAST32_MAX<<"\n";

  return 0;
}

The output of the above code is machine dependent. One of the possible output could be:

INT16_MIN: -32768
INT16_MAX: 32767
UINT16_MAX: 65535
INT_LEAST32_MIN: -2147483648
INT_LEAST32_MAX: 2147483647
UINT_LEAST32_MAX: 4294967295