Is there anything similar to Java's Integer.MIN_VALUE in C, which gives the smallest possible value of a signed integer, or do I just have to hard code the value myself?
Asked
Active
Viewed 7,130 times
3
-
Do not hard-code the value yourself; you will get the value wrong for some platforms that your code is moved to (because an `int` could have 16 bits, or 32 bits — by far the most common size — or 64 bits, or indeed other sizes). But it is good that you asked before heading in the wrong direction. – Jonathan Leffler Aug 22 '15 at 17:46
3 Answers
6
You can use limits.h
http://en.cppreference.com/w/c/types/limits
I think this is what you're looking for:
INT_MIN = minimum value for an int

joeya17
- 366
- 1
- 7
5
You will find INT_MIN
and INT_MAX
in <limits.h>
(for plain int). Indeed, the header defines the limits for all the integer types: signed char, short, plain int, long and long long, with the prefixes SCHAR_
, SHORT_
, INT_
, LONG_
and LLONG_
. All these are required to exist per ISO C99 and C11 (and, except for long long
, in C89).

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278

Jens
- 69,818
- 15
- 125
- 179