C User Input
scanf reads input typed by the user. You pass the address of the variable with &. This example reads from the keyboard, so on your own computer it waits for you to type; here it is shown with the input 7.
ExampleC
#include <stdio.h>
int main(void) {
int number;
printf("Type a number: ");
scanf("%d", &number);
printf("Your number plus one is %d\n", number + 1);
return 0;
}Output
Type a number: Your number plus one is 8
Quick check
Why does scanf need &number instead of number?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.