Data types tell the compiler what kind of data a variable will store — like numbers, characters, or decimals.
Think of data types as different boxes 📦 to store different kinds of items: numbers, letters, decimals, etc.
| Type | Meaning | Example |
|---|---|---|
int |
Integer (whole numbers) | 5, -10 |
float |
Decimal numbers | 3.14, -0.5 |
double |
More precise decimal | 3.14159265 |
char |
Single character | 'A', 'z' |
void |
No value | Used in functions |
Used to store whole numbers.
#include <stdio.h>
int main() {
int age = 20;
printf("Age: %d\n", age);
return 0;
}
%d is used for printing integer values.
Used for decimal numbers with ~6 digits of precision.
#include <stdio.h>
int main() {
float pi = 3.14;
printf("Value of pi: %.2f\n", pi);
return 0;
}
%.2f prints float with 2 decimal places.
Used for more accurate decimals than float.
#include <stdio.h>
int main() {
double price = 99.999999;
printf("Price: %.6lf\n", price);
return 0;
}
%.6lf is used for printing double values.
Used to store a single character.
#include <stdio.h>
int main() {
char grade = 'A';
printf("Your grade is: %c\n", grade);
return 0;
}
%c is used to print characters.
Used in functions that don’t return anything.
#include <stdio.h>
void sayHello() {
printf("Hello, World!\n");
}
int main() {
sayHello();
return 0;
}
void means the function doesn’t give anything back.
| Data Type | Format Specifier | Size (bytes) | Example |
|---|---|---|---|
int |
%d | 4 | 42 |
float |
%f | 4 | 3.14 |
double |
%lf | 8 | 3.141592 |
char |
%c | 1 | 'A' |
void |
- | 0 | (no value) |