Data types in C
Each variable in C has an associated data type. Each data type requires a different amount of memory and has some specific operations which can be performed over it.
Image shows the data types of C
Some examples of Primitive data type:
char : It stores a single character and requires 1 byte memory.
int : It stores integer value and requires 2 or 4 bytes memory dependent on the compiler.
float : It stores floating point values and requires 4 bytes of memory.
double : It also stores floating point values upto double precision.
Different data types have different ranges upto which they can store numbers. It may vary from compiler to compiler.
Data type | Size (Bytes) | Range | Format string |
---|---|---|---|
char | 1 | -128 to 127 | %c |
unsigned char | 1 | 0 to 255 | %c |
short or int | 2 | -32,768 to 32,767 | %d or %i |
unsigned int | 2 | 0 to 65,535 | %u |
long | 4 | -2147483648 to 2147483647 | %ld |
unsigned long | 4 | 0 to 4294967295 | %lu |
float | 4 | 3.4e-38 to 3.4e+38 | %f or %g |
double | 8 | 1.7e-308 to 1.7e+308 | %lf |
long double | 10 | 3.4e-4932 to 1.1e+4932 | %lf |
0 Comments