# difrence between int and long

• 12-28-2003
Benzakhar
difrence between int and long
what is the deference between int and long? I used sizeof() to check and they are the same in bytes.

• 12-28-2003
Zach L.
How big each type is depends on the system it is being run on. C++ guarantees only the following:

sizeof(short) <= sizeof(int) <= sizeof(long)
• 12-28-2003
Cris987
My book says that long is suppose to take up twice the size of int (8 to 4) . int can store numbers from -2147486648 to +2147486648 while long can store numbers from -9223372036854775808 to +9223372036854775808. However, the book also noted that the size of each variable form is determined by the compiler's developers.
• 12-28-2003
Zach L.
Right... C++ doesn't guarantee the exact size of anything, not even the number of bits in a byte. So, it depends on the compiler, and the system in which you are compiling. Many old Windows compilers had 16-bit ints and 32-bit longs. Now, on many Windows compilers, both are 32-bits. Often, it also has to do with the size of the registers in your compiler.
• 12-28-2003
Epo
You can also get numbers larger than those by using "unsigned"

This means that the range of numbers stays the same (I.e.):
-2147486648 to +2147486648 is a range of 4323273296 numbers.

"unsigned" tells it to ignore the negatives and begin counting at 0.

So, in the case of the above example:
"unsigned int X" would hold values from 0 to 4323273296.

But the range, again, depends on the compiler.
• 12-29-2003
Omnius
Quote:

Originally posted by Zach L.
How big each type is depends on the system it is being run on. C++ guarantees only the following:

sizeof(short) <= sizeof(int) <= sizeof(long)

Absolutely. In addition, it does guarantee the minimum sizes. A short int and a 'plain' int will be at least 16 bits (-32767 to 32767), a long int will be at least 32 bits (-2147483647 to 2147483647).