Page 1 of 1
What's the maximum integer in C?
Posted: Mon Mar 15, 2004 10:28 am
by zacharyleung
I believe it's 2^31 - 1. The thing is when I want to write code like the following
min = Integer.MAX_VALUE
for( i = ...)
if( min < value )
min = vale
So what is the maximum value, or where can I find it?
Thanks!

Posted: Mon Mar 15, 2004 11:55 am
by Adrian Kuegel
Yes, 2^31 - 1 is maximum integer in C.
You can include <limits.h> and use INT_MAX
Posted: Tue Mar 16, 2004 1:16 am
by horape
C doesn't define it. You can use limits.h to check the values available on your platform.
On the judge, int goes from -2^31 to 2^31-1, unsigned int from 0 to 2^32-1, long long -2^63 to 2^63-1 and unsigned long long 0 to 2^64-1.
Saludos,
HoraPe
Posted: Tue Mar 16, 2004 3:24 am
by zacharyleung
Ah, ok, thanks!
Posted: Tue Mar 16, 2004 5:29 pm
by Krzysztof Duleba
horape, you're right only to some extend. C standard does define that
1=sizeof(char) <=sizeof(short) <= sizeof(int) <=sizeof(long) <=sizeof(long long)
and that
char stores at least 1 byte
short stores at least 2 bytes
long stores at least 4 bytes
long long stores at least 8 bytes.
Everything else is up to compiler.