# **[](https://en.cppreference.com/w/c/header/limits)** provides platform-specific integer type limits: `INT_MAX`, `INT_MIN`, `UINT_MAX`, `LONG_MAX`, etc. Use these when writing portable code that works correctly regardless of whether integers are 32 or 64 bits. Never hardcode values like `2147483647` directly; use the macros instead. ## Example This example queries integer limits and demonstrates overflow checking. ```c // compile: gcc -o limitsexample limitsexample.c // run: ./limitsexample // description: query integer limits and check for overflow #include #include int main() { printf("INT_MAX = %d\n", INT_MAX); printf("INT_MIN = %d\n", INT_MIN); printf("UINT_MAX = %u\n", UINT_MAX); printf("LONG_MAX = %ld\n", LONG_MAX); int a = INT_MAX, b = 1; if (a > INT_MAX - b) printf("INT_MAX + 1 would overflow\n"); unsigned int u = UINT_MAX; printf("UINT_MAX + 1 = %u (wraps to 0)\n", u + 1); return 0; } ``` ## Common macros **Signed integer limits**: - `CHAR_MIN`, `CHAR_MAX`: char (may be signed or unsigned depending on platform) - `SCHAR_MIN`, `SCHAR_MAX`: signed char - `SHRT_MIN`, `SHRT_MAX`: short - `INT_MIN`, `INT_MAX`: int - `LONG_MIN`, `LONG_MAX`: long - `LLONG_MIN`, `LLONG_MAX`: long long **Unsigned integer limits**: - `UCHAR_MAX`: unsigned char - `USHRT_MAX`: unsigned short - `UINT_MAX`: unsigned int - `ULONG_MAX`: unsigned long - `ULLONG_MAX`: unsigned long long (C99) **Character and bit information**: - `CHAR_BIT`: number of bits in char (typically 8) - `CHAR_MIN`, `CHAR_MAX`: depends on signedness of char on platform - `MB_LEN_MAX`: max bytes in multibyte character **Portable sizing**: - Use these macros instead of hardcoding 32 or 64 for portable code - For fixed-width types, use `` instead (e.g., `INT32_MAX`) - `` defines platform-dependent limits