Datatypes tell the compiler what kind of value a variable will and hence allocate the size to that variable accordingly.
Various types of datatype supported by C/CPP are:
Integer Types:
TYPE | SIZE | RANGE | FORMAT |
short int | 2 byte | -32,768 to 32,767 | %hd |
unsigned short int | 2 byte | 0 to 65,535 | %hu |
unsigned int | 4 byte | 0 to 4,294,967,295 | %u |
int | 4 byte | -2,147,483,648 to 2,147,483,647 | %d |
long int | 4 byte | -2,147,483,648 to 2,147,483,647 | %ld |
unsigned long int | 4 byte | 0 to 4,294,967,295 | %lu |
long long int | 8 byte | -(2^63) to (2^63)-1 | %lld |
unsigned long long int | 8 byte | 0 to 18,446,744,073,709,551,615 | %llu |
signed char | 1 byte | -128 to 127 | %c |
unsigned char | 1 byte | 0 to 255 | %c |
Floating Point types:
TYPE | SIZE | PRECISION | FORMAT |
float | 4 | 6 decimal | %f |
double | 8 | 15 decimal | %lf |
long double | 12 | 19 decimal | %Lf |