English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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.
Macro | Value | Description |
---|---|---|
CHAR_BIT | 8 | Define the number of bits in a byte. |
SCHAR_MIN | -128 | Define the minimum value of a signed character. |
SCHAR_MAX | 127 | Define the maximum value of a signed character. |
UCHAR_MAX | 255 | Define the maximum value of an unsigned character. |
CHAR_MIN | 0 | The minimum value defined for the type char, if char represents a negative value, its value equals SCHAR_MIN, otherwise it equals 0. |
CHAR_MAX | 127 | Define the maximum value of type char, if char represents a negative value, its value equals SCHAR_MAX, otherwise it equals UCHAR_MAX. |
MB_LEN_MAX | 1 | Define the maximum number of bytes in a multibyte character. |
SHRT_MIN | -32768 | Define the minimum value of a short integer. |
SHRT_MAX | +32767 | Define the maximum value of a short integer. |
USHRT_MAX | 65535 | Define the maximum value of an unsigned short integer. |
INT_MIN | -32768 | Define the minimum value of an integer. |
INT_MAX | +32767 | Define the maximum value of an integer. |
UINT_MAX | 65535 | Define the maximum value of an unsigned integer. |
LONG_MIN | -2147483648 | Define the minimum value of a long integer. |
LONG_MAX | +2147483647 | Define the maximum value of a long integer. |
ULONG_MAX | 4294967295 | Define the maximum value of an unsigned long integer. |
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