Why is LONG_MAX Values the same as INT_MAX? I'm also getting error when doing something like: long number = 241421; but It can be fixed by doing long long number = 241421;
long and int are not the same thing. sizeof(int) is guaranteed to be <= sizeof(long), but they are not guaranteed to be the same. Deviations between compilers can occur.
You should use std::numeric_limits<type>::max()
On my machine, this is what I get printed out:
char is 8 bits. Short is at least 16 bits, int is at least 16 bits, long is at least 32 bits, long long is at least 64 bits.
But "at least" doesn't mean their sizes cannot be larger.
char is 1 byte and CHAR_BIT wide. CHAR_BIT is equal to the byte width of the platform. Although now extremely rare, platforms with non-octet bytes do exist.
Same compiler (e.g. GCC) can exists on many platforms, and won't use the same limits everywhere.
Note that many 64-bit environments support both 32-bit and 64-bit binaries, and the versions have different limits. Same compiler -- with different options -- can create both versions.