There are all sorts of variables that can be used for numbers. Each one is used for a specific range or a specific type of number.
int : This variable is used for integers ranging from -32 768
to 32 767. It uses 2 bytes of memory. But there is another
variable type that is called
short.
It has the same range, but is also used as the opposite of the long
variable type.
unsigned int : This variable is used for integers ranging from 0 to 65 535. It uses 2 bytes of memory.
long : This variable is use for integers ranging from -2 147 483 648 to 2 147 483 647. It uses 4 bytes of memory.
unsigned long : This variable type is used for integers ranging from 0 to 4 294 967 295. It uses 4 bytes of memory.
You may have noticed the unsigned characters. They only store
non negative numbers in memory. Also, some compilers may have the
int
character have 4 bytes instead of 2. That's why the short
character exists. The int in those compilers has a range that
is the same as the long character. The short only used
2 bytes, which saves on memory.
The variable types in the above are called INTEGER TYPES. The next kind of variable type are called FLOATING POINT TYPES. The are used when the user or any calculation done might or will give decimal numbers.
float : This variable type is used for decimals ranging from
3.4 x 10-38 to 3.4 x 1038. This also includes
the negative numbers.
It uses 4 bytes of memory and has a 7 digit precision..
double : This variable type is used for decimals ranging from
1.7 x 10-308 to 1.7 x 10308. This also includes
the negative
numbers. It uses 8 bytes of memory and has a 15 digit precision.
long double : This variable type is used for decimals ranging
from 3.4 x 10-4932 to 1.1 x 104932. This also includes
the negative
numbers. It uses 10 bytes of memory and has a 19 digit precision.
The reason that there are so many types is that not only is it a memory
thing, but a matter of speed. Using the appropriate variable type
for a number makes the program run more efficiently.