Lesson 2: Variables & types — int, double, char
In the previous lesson we printed fixed text; now we'll learn to store data. C is a statically typed language — every variable is declared with a type: int for whole numbers, double for decimal numbers, char for a single character in single quotes ('A'). To print a variable you embed a specifier in
Variables are like labeled jars in a kitchen: each jar says what may go inside — sugar, flour, or coffee. In C you must choose the jar's kind (the type) before putting anything in, and you can't pour soup into the sugar jar.
- variable
- A named, typed memory cell that stores a value, e.g. int age = 25;.
- type
- Determines what data the variable holds: int whole, double decimal, char single character.
- %d specifier
- A placeholder inside a printf string where an int value goes. %f for double and %c for char.
- char
- A type for a single character, written in single quotes: 'A' — not in double quotes.