← GCC/C Index

📏 <limits.h> — Integer Type Limits

Defines min/max values for all integer types on the current platform.

Include: #include <limits.h> | Compile: gcc -Wall -o prog prog.c

📋 Functions & Macros

NamePrototype / ValueDescription
CHAR_BIT8Bits in a char
SCHAR_MIN-128Minimum value of signed char
SCHAR_MAX127Maximum value of signed char
UCHAR_MAX255Maximum value of unsigned char
SHRT_MIN-32768Minimum value of short
SHRT_MAX32767Maximum value of short
INT_MIN-2147483648Minimum value of int
INT_MAX2147483647Maximum value of int
UINT_MAX4294967295Maximum value of unsigned int
LONG_MAX9223372036854775807Maximum value of long (64-bit)
LLONG_MAX9223372036854775807Maximum value of long long

💡 Example Program

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 */

← <stdbool.h>  |  🏠 Index  |  <assert.h> →