C Data Types
Data Types
Each data type requires different amounts of memory and has some specific operations which can be performed over it. A variable in C must be a specified data type, and must use a format specifier inside the printf() function to display it:
Common data types used in C:
- char: It stores a single character and requires a single byte of memory
- char: It stores a single character and requires a single byte of memory
- float: It is used to store decimal numbers with single precision.
- double: It is used to store decimal numbers with double precision.
Data Types | Memory Size | Range |
---|---|---|
char | 1 byte | −128 to 127 |
signed char | 1 byte | −128 to 127 |
unsigned char | 1 byte | 0 to 255 |
short | 2 byte | −32,768 to 32,767 |
signed short | 2 byte | −32,768 to 32,767 |
unsigned short | 2 byte | 0 to 65,535 |
int | 2 byte | −32,768 to 32,767 |
signed int | 2 byte | −32,768 to 32,767 |
unsigned int | 2 byte | 0 to 65,535 |
short int | 2 byte | −32,768 to 32,767 |
signed short int | 2 byte | −32,768 to 32,767 |
unsigned short int | 2 byte | 0 to 65,535 |
long int | 4 byte | long int 4 byte -2,147,483,648 to 2,147,483,647 |
signed long int | 4 byte | signed long int 4 byte -2,147,483,648 to 2,147,483,647 |
unsigned long int | 4 byte | 0 to 4,294,967,295 |
float | 4 byte | |
double | 8 byte | |
long double | 10 byte |
Basic Format Specifiers
There are different format specifiers for each data type. Here are some of them:
Format Specifier | Data Type |
---|---|
%d or %i | int |
%f | float |
%c | char |
%s | strings, |
%hd | short int |
%hu | unsigned short int |
%u | unsigned int |
%ld | long int |
%lu | unsigned long int |
%lld | long long int |
%llu | unsigned long long int |
%c | signed char |
%c | unsigned char |
%lf | double |
%Lf | long double |