What's the maximum integer in C?

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
New poster
Posts: 14
Joined: Tue Feb 03, 2004 3:43 am

What's the maximum integer in C?

Post 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! :)

Adrian Kuegel
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

Yes, 2^31 - 1 is maximum integer in C.
You can include <limits.h> and use INT_MAX

New poster
Posts: 49
Joined: Sat Sep 13, 2003 3:18 pm
Location: Buenos Aires

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


New poster
Posts: 14
Joined: Tue Feb 03, 2004 3:43 am

Post by zacharyleung »

Ah, ok, thanks!

Krzysztof Duleba
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland

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

Post Reply

Return to “C”