Datatype | Range | Byte | Format Specifier | |
---|---|---|---|---|
signed char | -128 to + 127 | 1 | %c | |
unsigned char | 0 to 255 | 1 | %c | |
short signed int | -32768 to +32767 | 2 | %d | |
short unsigned int | 0 to 65535 | 2 | %u | |
signed int | -32768 to +32767 | 2 | %d | |
unsigned int | 0 to 65535 | 2 | %u | |
long signed int | -2147483648 to +2147483647 | 4 | %ld | |
long unsigned int | 0 to 4294967295 | 4 | %lu | |
float | -3.4e38 to +3.4e38 | 4 | %f | |
double | -1.7e308 to +1.7e308 | 8 | %lf | |
long double | -1.7e4932 to +1.7e4932 | 10 | %Lf |
The difference between signed and unsigned
If we know that a value will always be positive then we declare it using the keyword "unsigned". This will increase the the range of the integer from to 0 to 65535. This is quite useful when the value is sure to be positive.
Float or Int
Some freshers argue that if can use float to use integer values also then why do we use int. The answer lies in third column of the above table. An integer variable takes 2 bytes from the memory while a float variables uses 4 bytes. This means that an integer variable takes half the amount of memory if compared to a float variable.
0 comments:
Post a Comment