Data types in C tell the compiler what type of data a variable will hold. Each variable in C must be declared with a data type, which determines the size and layout of the variable's memory.
๐ Tip: Using the right data type ensures efficient memory usage and better performance.
Data Type | Size (bytes) | Description |
---|---|---|
int | 4 | Stores integers (whole numbers) |
float | 4 | Stores decimal numbers (6-7 digits precision) |
double | 8 | Stores large decimal numbers (15-16 digits precision) |
char | 1 | Stores single characters (e.g., 'A') |
#include <stdio.h> int main() { int age = 21; float pi = 3.14; double bigDecimal = 12345.6789; char grade = 'A'; printf("Age: %d\\n", age); printf("Pi: %.2f\\n", pi); printf("Big Decimal: %.4lf\\n", bigDecimal); printf("Grade: %c\\n", grade); return 0; }
%d
โ for int%f
โ for float%lf
โ for double%c
โ for char%.2f
or %.4lf
in printf
to control decimal places.
%d
for float
)printf
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!