int
We can use int
for declaring an integer variable:
Type | Storage size | Value range |
---|---|---|
Char | 1 byte | -128 to 127 or 0 to 255 |
unsigned char | 1 byte | 0 to 255 |
signed char | 1 byte | -128 to 127 |
Int | 2 or 4 bytes | -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 |
Short | 2 bytes | -32,768 to 32,767 |
unsigned short | 2 bytes | 0 to 65,535 |
Long | 4 bytes | -2,147,483,648 to 2,147,483,647 |
unsigned long | 4 bytes | 0 to 4,294,967,295 |
To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator.
float
In C, floating-point numbers can also be represented in exponential. For example:
Type | Storage size | Value range | Precision |
---|---|---|---|
float | 4 byte | 1.2E-38 to 3.4E+38 | 6 decimal places |
double | 8 byte | 2.3E-308 to 1.7E+308 | 15 decimal places |
long double | 10 byte | 3.4E-4932 to 1.1E+4932 | 19 decimal places |
Set Decimal Precision
You have probably already noticed that if you print a floating point number, the output will show many digits after the decimal point:
Example:
If you want to remove the extra zeros (set decimal precision), you can use a dot (.
) followed by a number that specifies how many digits that should be shown after the decimal point:
Example:
Aritmetic operations on numbers
C Arithmetic Operators C Increment and Decrement Operators