C Standard Library
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C - <stdint.h>



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

C <stdint.h> Types

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

Signed TypeUnsigned TypeDescription
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 <stdint.h> Macros

The below mentioned macros are implementation-specific and defined with the #define directive. The below table shows the different macros in <stdint.h> 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_MAXMaximum value of an object of type size_t(264-1), or higher
PTRDIFF_MINMinimum value of an object of type ptrdiff_t-(216-1), or lower
PTRDIFF_MAXMaximum value of an object of type ptrdiff_t(216-1), or higher
SIG_ATOMIC_MINMinimum 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_MAXMaximum 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_MINMinimum value of an object of wchar_t typeif wchar_t is signed: -127, or lower; if wchar_t is unsigned: 0
WCHAR_MAXMaximum value of an object of wchar_t typeif wchar_t is signed: 127, or higher; if wchar_t is unsigned: 255, or higher
WINT_MINMinimum value of an object of wint_t typeif wint_t is signed: -32767, or lower; if wint_t is unsigned: 0
WINT_MAXMaximum 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 <stdint.h> library.

#include <stdio.h>
#include <stdint.h>

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

  //displaying maximum and minimum value
  printf("INT16_MIN: %d\n", INT16_MIN);
  printf("INT16_MAX: %d\n", INT16_MAX); 
  printf("UINT16_MAX: %d\n", UINT16_MAX); 
  printf("INT_LEAST32_MIN: %d\n", INT_LEAST32_MIN);
  printf("INT_LEAST32_MAX: %d\n", INT_LEAST32_MAX);

  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

5