C Tutorial · Chapter 8 of 16
C Input
Read values from the user with scanf.
scanf reads console input into variables. For numbers, pass the address with &.
Always guide the user with a clear printf prompt before reading input.
Input sample
Try it Yourself »
#include <stdio.h>
int main(void) {
char name[50];
int age;
printf("Enter your name: ");
scanf("%49s", name);
printf("Enter your age: ");
scanf("%d", &age);
printf("Hello %s, you are %d years old.\n", name, age);
return 0;
}
Classroom Tips
- Forgetting & with scanf is a classic bug.
- Provide Console Input before Run when needed.