On this page
INT_MAX
Prev: limits.h | Up: limits.h | Next: CHAR_BIT
Rel: limits.h, stdint, stdbool & limits Guide
Ref: cppreference — INT_MAX
Tags: #public #prog #c #stdlib #limits #tier/core
Include
#include <limits.h>
Signature & Overview
#define INT_MAX /* >= 32767; 2147483647 on 32-bit int */
Maximum (and INT_MIN minimum) representable values of int.
Notes & Pitfalls
- Check before adding to prevent signed overflow UB: Write
if (a > INT_MAX - b)rather thanif (a + b > INT_MAX).
Example
#include <assert.h>
#include <limits.h>
int main(void) {
int a = INT_MAX - 5, b = 10;
assert(a > INT_MAX - b); // safe overflow check
}
Linked from
Related notes
- tuts/c/stdlib/limits/CHAR_BIT Linked here; links to this page; shared tags: #c, #limits, #prog, #stdlib, #tier
- tuts/c/stdlib/limits Linked here; links to this page; shared tags: #c, #limits, #prog, #stdlib
- tuts/c/stdlib/stdint_stdbool_and_limits Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/limits/DBL_EPSILON shared tags: #c, #limits, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isspace shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/tolower shared tags: #c, #prog, #stdlib, #tier