scanf()
Reads input from the user.
Syntax
scanf("%d", &variable)Description
Reads from the keyboard. The ADDRESS (&) of the variable is provided. & is not needed for string arrays.
Example
Loading editor…
This language is for reference/learning only — copy the code and try it in your own environment.
Expected output
(depending on the entered number) You entered: 5
When to use?
Console input.
Common mistakes
- ⚠️ Forgetting the & sign causes a crash: scanf("%d", &x).