Range of int and long datatypes

I found out that the range is int and long on 32 bit windows:

signed int: -32767 to 32767
signed long: -2147483647 to 2147483647

      

why does int have the same range as long as msdn says? http://msdn.microsoft.com/en-us/library/s3f49ktz%28VS.80%29.aspx

+2


a source to share


5 answers


I assume you intended to write this:

signed int: -2147483647 to 2147483647
...

      



They are the same for completely historical reasons. The C ++ standard does not specify a specific size for each type, the only guarantee between the two is sizeof(int) <= sizeof(long)

.

0


a source


Your premise is wrong. int

and long

are 32-bit (both) 32 and 64-bit Windows.



+2


a source


the exact length is not required. It is asserted that long cannot be less than int.

http://www.faqs.org/docs/learnc/x401.html

+1


a source


You will be comparing to __int16, whereas your long will be comparing to __int32.

To do this, you need to look at the Bytes columns to make more sense.

0


a source


When working with binary representations of integers, you can calculate the maximum range of signed data types based on the number of bits used to represent the data using the formula:

low value: -2 ^ (N-1) highest value: 2 ^ (N-1) - 1

where N is the number of bits.

For one reason or another, the "signed int" type you are talking about is represented by 16 bits, and the "signed long" is represented by 32 bits.

Also note that the ranges you posted appear to be incomplete, note that the 16 bit signed int range goes to -32768 which is lower than your range.

0


a source







All Articles