English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C Standard Library <limits.h>

limits.h The header file determines various attributes of various variable types. Macros defined in this header file limit the values of various variable types (such as char, int, and long).

These limitations specify that variables cannot store any values that exceed these limitations, for example, the maximum value that an unsigned integer can store is 255.

Library Macro

The following values are specific to the implementation and are defined by the #define directive. These values must not be less than the values given below.

MacroValueDescription
CHAR_BIT8Define the number of bits in a byte.
SCHAR_MIN-128Define the minimum value of a signed character.
SCHAR_MAX127Define the maximum value of a signed character.
UCHAR_MAX255Define the maximum value of an unsigned character.
CHAR_MIN0The minimum value defined for the type char, if char represents a negative value, its value equals SCHAR_MIN, otherwise it equals 0.
CHAR_MAX127Define the maximum value of type char, if char represents a negative value, its value equals SCHAR_MAX, otherwise it equals UCHAR_MAX.
MB_LEN_MAX1Define the maximum number of bytes in a multibyte character.
SHRT_MIN-32768Define the minimum value of a short integer.
SHRT_MAX+32767Define the maximum value of a short integer.
USHRT_MAX65535Define the maximum value of an unsigned short integer.
INT_MIN-32768Define the minimum value of an integer.
INT_MAX+32767Define the maximum value of an integer.
UINT_MAX65535Define the maximum value of an unsigned integer.
LONG_MIN-2147483648Define the minimum value of a long integer.
LONG_MAX+2147483647Define the maximum value of a long integer.
ULONG_MAX4294967295Define the maximum value of an unsigned long integer.

Online Example

The following example demonstrates the use of some constants defined in the limit.h file.

#include <stdio.h>
#include <limits.h>
int main()
{
   printf("The number of bits in byte %d\n", CHAR_BIT);
   printf("The minimum value of SIGNED CHAR = %d\n", SCHAR_MIN);
   printf("The maximum value of SIGNED CHAR = %d\n", SCHAR_MAX);
   printf("The maximum value of UNSIGNED CHAR = %d\n", UCHAR_MAX);
   printf("The minimum value of SHORT INT = %d\n", SHRT_MIN);
   printf("The maximum value of SHORT INT = %d\n", SHRT_MAX); 
   printf("The minimum value of INT = %d\n", INT_MIN);
   printf("The maximum value of INT = %d\n", INT_MAX);
   printf("The minimum value of CHAR = %d\n", CHAR_MIN);
   printf("The maximum value of CHAR = %d\n", CHAR_MAX);
   printf("The maximum value of LONG = %ld\n", LONG_MIN);
   printf("The minimum value of LONG = %ld\n", LONG_MAX);
  
   return(0);
}

Let's compile and run the above program, which will produce the following results:

The number of bits in byte 8
The minimum value of SIGNED CHAR = -128
The maximum value of SIGNED CHAR = 127
UNSIGNED CHAR maximum value = 255
SHORT INT minimum value = -32768
SHORT INT maximum value = 32767
INT minimum value = -32768
INT maximum value = 32767
CHAR minimum value = -128
CHAR maximum value = 127
LONG maximum value = -2147483648
LONG minimum value = 2147483647