Lesson 3: Input with scanf & debugging
Until now our programs only talked; now they'll also listen. scanf("%d", &age); reads a number the user types into the variable — the & hands scanf the variable's address (we'll understand it deeply in the pointer lessons). The standard pattern: a printf that shows a prompt, then a scanf that reads.
scanf is like a pizza courier: it's not enough to say 'deliver to Danny' — you must give an address. The & before the variable is exactly that: Danny's address, so the courier knows where to deliver the number the user typed.
- scanf
- A function that reads user input by specifier: scanf("%d", &age); reads an int.
- & (address operator)
- Gives scanf the variable's memory address so it can write into it. We'll go deeper in the pointer lessons.
- warning
- A gcc message about suspicious code that compiles but is probably wrong. gcc -Wall shows them all — always read and fix.
- debugging
- Finding and fixing bugs: reading the compiler error by its line number, or printing intermediate values with printf.