21

Possible Duplicates:
How would you set a variable to the largest number possible in C?
maximum value of int

I need to use the maximum integer value in my my code, but I don't want to explicitly write 4294967295. Is it defined somewhere?

Community
  • 1
  • 1
snakile
  • 50,186
  • 60
  • 164
  • 235

6 Answers6

38

INT_MAX (for int) or UINT_MAX (for unsigned int) defined in <limits.h>

James McNellis
  • 338,529
  • 73
  • 897
  • 968
6

Use limits.h:

#include <limits.h>

int maximum = INT_MAX;
GManNickG
  • 478,574
  • 51
  • 478
  • 539
4

There shall be a constant in limits.h, if I'm not mistaken it shall be INT_MAX

rano
  • 5,556
  • 4
  • 37
  • 64
3
#include <limits.h>

INT_MAX
Donal Fellows
  • 126,337
  • 18
  • 137
  • 204
alxx
  • 9,902
  • 4
  • 25
  • 40
2

INT_MAX as defined in <limits.h>

t0mm13b
  • 33,483
  • 8
  • 75
  • 107
2

The include file stdint.h includes all different macros for the different integer types. In particular UINTMAX_MAX for uintmax_t.

Jens Gustedt
  • 74,635
  • 5
  • 99
  • 170