Defines min/max values for all integer types on the current platform.
Include: #include <limits.h> | Compile: gcc -Wall -o prog prog.c
| Name | Prototype / Value | Description |
|---|---|---|
| CHAR_BIT | 8 | Bits in a char |
| SCHAR_MIN | -128 | Minimum value of signed char |
| SCHAR_MAX | 127 | Maximum value of signed char |
| UCHAR_MAX | 255 | Maximum value of unsigned char |
| SHRT_MIN | -32768 | Minimum value of short |
| SHRT_MAX | 32767 | Maximum value of short |
| INT_MIN | -2147483648 | Minimum value of int |
| INT_MAX | 2147483647 | Maximum value of int |
| UINT_MAX | 4294967295 | Maximum value of unsigned int |
| LONG_MAX | 9223372036854775807 | Maximum value of long (64-bit) |
| LLONG_MAX | 9223372036854775807 | Maximum value of long long |
Copy, save as demo.c, and compile with the command shown at the bottom.
#include <stdio.h>
#include <limits.h>
int main(void) {
printf("CHAR_BIT = %d\n", CHAR_BIT);
printf("INT_MIN = %d\n", INT_MIN);
printf("INT_MAX = %d\n", INT_MAX);
printf("UINT_MAX = %u\n", UINT_MAX);
printf("LONG_MAX = %ld\n", LONG_MAX);
printf("LLONG_MAX = %lld\n", LLONG_MAX);
int a = INT_MAX;
if (a == INT_MAX)
printf("Adding 1 to INT_MAX will overflow!\n");
return 0;
}
/* Compile: gcc -Wall -o limits_demo limits_demo.c */