C Standard Library

C - <limits.h>



The C <limits.h> header file defines constants with the limits of fundamental integral types for the specific system and compiler implementation used. The limits for fundamental floating-point types are defined in <float.h>. The limits for width-specific integral types and other typedef types are defined in <stdint.h>.

C <limits.h> Macro Constants

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

MacrosDescriptionValue
CHAR_BITNumber of bits in a char object (byte) 8 or greater
SCHAR_MINMinimum value for an object of type signed char (-27+1) or less
SCHAR_MAXMaximum value for an object of type signed char (27-1) or greater
UCHAR_MAXMaximum value for an object of type unsigned char (28-1) or greater
CHAR_MINMinimum value for an object of type char either SCHAR_MIN or 0
CHAR_MAXMaximum value for an object of type char either SCHAR_MAX or UCHAR_MAX
MB_LEN_MAXMaximum number of bytes in a multi-byte character, for any locale 1 or greater
SHRT_MINMinimum value for an object of type short int (-215+1) or less
SHRT_MAXMaximum value for an object of type short int (215-1) or greater
USHRT_MAXMaximum value for an object of type unsigned short int (216-1) or greater
INT_MINMinimum value for an object of type int (-215+1) or less
INT_MAXMaximum value for an object of type int (215-1) or greater
UINT_MAXMaximum value for an object of type unsigned int (216-1) or greater
LONG_MINMinimum value for an object of type long int (-231+1) or less
LONG_MAXMaximum value for an object of type long int (231-1) or greater
ULONG_MAXMaximum value for an object of type unsigned long int (232-1) or greater
LLONG_MIN (C99)Minimum value for an object of type long long int (-263+1) or less
LLONG_MAX (C99)Maximum value for an object of type long long int (263-1) or greater
ULLONG_MAX (C99)Maximum value for an object of type unsigned long long int (264-1) or greater

Example:

The example below describes the working of macros constant of C <limits.h> library.

#include <stdio.h>
#include <limits.h>

int main (){

  printf("CHAR_BIT: %i\n", CHAR_BIT);
  printf("CHAR_MIN: %i\n", CHAR_MIN);
  printf("CHAR_MAX: %i\n", CHAR_MAX);  
  printf("SHRT_MIN: %i\n", SHRT_MIN);
  printf("SHRT_MAX: %i\n", SHRT_MAX);  
  printf("LONG_MIN: %li\n", LONG_MIN);
  printf("LONG_MAX: %li\n", LONG_MAX);
  printf("LLONG_MIN: %lli\n", LLONG_MIN);
  printf("LLONG_MAX: %lli\n", LLONG_MAX);
  return 0;
}

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

CHAR_BIT: 8
CHAR_MIN: -128
CHAR_MAX: 127
SHRT_MIN: -32768
SHRT_MAX: 32767
LONG_MIN: -9223372036854775808
LONG_MAX: 9223372036854775807
LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807