C/C++ Arena

Step 1 of 5

Read a number

scanf is the mirror image of printf: it reads values from input (stdin) into variables.

int n;
scanf("%d", &n);

The & means "the address of n". scanf needs to know where to store the value, not what's currently in it. Forgetting & is the #1 scanf bug.

On this site, each test feeds the program some input. Use Run with my input to try your own.

Your turn: read an int and print it doubled. Input 21 prints 42.

Next: Several values at once