C - Get smallest possible signed integer

7.6k Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER

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

0
On

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).

0
On

In header limits.h you will get minimum and maximum value of data types.

For integer you can use -

  INT_MAX            //max value for signed integer

  INT_MIN           //min value for signed integer