An integer constant is any number in the range -32768 to +32767. This is because an integer constant always occupies two bytes in memory.
long integers cause the program to run a bit slower. The value of a long integer can vary from -2147483648 and +2147483647.
short as well integers which need less space in memory and thus help speed up program execution. In fact, a short int is nothing but our ordinary int.
short int j;
short int height;
Sometimes, we know in advance that the value stored in a given integer variable will always be positive. In such a case we can declare the variable to be unsigned, Example:
unsigned int num_student;
ð With such a declaration, the range of permissible integer value will shift from the range -32768 to +32767 to the range 0 to 65535. Note that an unsigned integer still occupied two bytes. In fact an unsigned int is nothing but a short unsigned int. Thus, all the following declarations are same:
short unsigned int i;
unsigned int i;
There also exists a long unsigned int which has a range of 0 to 4294967295 and occupies four bytes of memory.
Chars with signed and unsigned
There are signed and unsigned chars, both occupying one byte each, but having different ranges. A signed char is same as our ordinary char and has a range from -128 to +127; whereas an unsigned char has a range from 0 to 225.
unsigned char ch;
for(ch = 0 ; ch = 254 ; ch++ )
Floats and Doubles
A float occupies four bytes in memory and can range from -3.4e38 to +3.4e38. If this is insufficient then C++ offers a double data type which occupies 8 bytes in memory and has a range from -1.7e308 to +1.7e308.
float n, decimal_num;
double a, population;
If the situation demands usage of real numbers which lie even beyond the range offered by double data type then there exists a long double which can range from -1.7e4932 to +1.7e4932. A long double occupies 10 bytes in memory.
long double n, world_population;
|signed char||-128 to +127||1|
|unsigned char||0 to 255||1|
|short signed int||-32768 to +32767||2|
|short unsigned int||0 to 65535||2|
|long signed int||-2147483648 to +2147483647||4|
|long unsigned int||0 to 4294967295||4|
|float||-3.4e38 to +3.4e38||4|
|double||-1.7e308 to +1.7e308||8|
|long double||-1.7e4932 to +1.7e4932||10|
unsigned char d;
unsigned int j;
long int k;
unsigned long int m;
long double z;