ranges of int and long same in my computer. why??

I am getting the same output for ranges of int and long in my computer(both give 2*10^9), but long long gives correct output. why is size of int as big as long? I use gcc 4.8.1 compiler

std::cout << "Minimum value for long long: " << std::numeric_limits<"long long>::min() << '\n';

std::cout << "Maximum value for long long: " << std::numeric_limits<long long>::max() << '\n';

so generally for numbers less than 10^9 I use int only, today I suffered because of this in the december cook-off

Because that’s the way it is in C/C++, datatype sizes are not well defined as for example in Java - http://www.cplusplus.com/doc/tutorial/variables/

signed long int - Not smaller than int. At least 32 bits.

1 Like

what ranges does codechef have for int and long??

I do not know really, I’m using int and long long

Codechef uses sphere engine like spoj.

According to ideone (also running sphere engine),

int and long are both 4 bytes (32 bits) and long long int is 8 bytes or 64 bits (atleast in C).

Check this for more a demo on ideone (on gcc 4.8.1).

Also check the link by @betlista :diamonds::diamonds:, a good discussion is there.

2 Likes

http://msdn.microsoft.com/en-us/library/s3f49ktz(v=vs.90).aspx

According to this link, modern compiler i.e. For 32-bit and 64-bit compilers size of int and long is 4 bytes. But the main thing to note is that int and long are not same, because according to standard

The standard only requires ints to be stored in at least 16 bits, and longs in 32 bits.

1 Like