User Input
scanf reads formatted input and needs the address of the variable (&age). fgets reads a whole line safely. Input cannot be typed on this page, so the example uses a sample session.
Example
#include <stdio.h>
int main(void) {
int age;
printf("Age: ");
scanf("%d", &age);
printf("Next year you will be %d\n", age + 1);
return 0;
}
// sample run:
// Age: 30
// Next year you will be 31Exercise
Pass the address of the variable.
scanf("%d", age);
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.