Data Types
int, float, and char — whole numbers, decimals, and letters.
3 minute read
Big idea
The type says what kind of value a variable can hold.
The idea
Three types you'll use all the time:
| Type | Holds | Example | Print with |
|---|---|---|---|
int | whole numbers | int count = 7; | %d |
float | decimals | float price = 9.5; | %f |
char | one character | char grade = 'A'; | %c |
Example
#include <stdio.h>
int main(void) {
int count = 7;
float price = 9.5;
char grade = 'A';
printf("%d\n", count);
printf("%.2f\n", price);
printf("%c\n", grade);
return 0;
}output
7
9.50
ARun and edit it in the app.
%.2f means "show 2 digits after the decimal point".
Watch it
Think of it like
Different containers for different things: a coin box for whole coins, a measuring cup for amounts like 9.5, and a name tag with room for just one letter.
🕷️ Spidey-sense: You wouldn't carry web fluid in a paper bag. A type is the right container for the job:
intfor whole numbers,floatfor decimals,charfor a single letter. Pick the container first, then put things in.
Common mistake
A char uses single quotes. Double quotes are for text (strings).
char grade = "A"; // ✗
char grade = 'A'; // ✓
Key terms
- int — A whole number, like 7 or -3.
- float — A number with a decimal point, like 9.5.
- char — A single character, like 'A'.
Check yourself
Which type stores a decimal number like 3.14?
Which is the right way to store the letter A?
Which format code prints an int?