numerical range of int and short
The range for short is: -32,768 to 32,767
The range for int is: -2,147,483,648 to 2,147,483,647
(int is system dependent which means that on 16-bit system it would be occupy 2 bytes which would result in small numerical range)
The simple way to know the range for short is (the same goes for int): There are 2 bytes occupied by a short. There are 16 bits in 2 bytes. 2^16 = 65536. Now divide the "65536" by 2 to get -ve and +ve ranges. 65536/2 = 32768. Now we have to include "0" too in the range. The -ve range is: -32,768, and +ve range is: 32,767. The question which can come to mind is that why the +ve range is not "32,768" instead of "32,767". Let's check a simple case to understand this.
When 30 is divided by 2, the result is 15. This result doesn't include "0" and "0" is only used as a reference. But if we were to include "0" also then the +ve and -ve range for 30 would be: -15 to +14.
I hope you understand my question. Please guide me on this. Thank you.