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
  • 52,936
  • 62
  • 169
  • 241

6 Answers6

38

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

James McNellis
  • 348,265
  • 75
  • 913
  • 977
6

Use limits.h:

#include <limits.h>

int maximum = INT_MAX;
GManNickG
  • 494,350
  • 52
  • 494
  • 543
4

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

rano
  • 5,616
  • 4
  • 40
  • 66
3
#include <limits.h>

INT_MAX
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
alxx
  • 9,897
  • 4
  • 26
  • 41
2

INT_MAX as defined in <limits.h>

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
2

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

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177