Reading data From Keyboard
scanf(“control string”, &variable01, &variable02, …);
=> The ampersand symbol, &, is very important. It’s an operator specifying the variable name’s address. Omitting it, might result into unexpected results.
How Does Scanf Behave During Execution
Consider: scanf(“%d”, &number);
=> This statement halts execution and waits for a value to be entered. That value will be stored in a variable ‘number‘ and is of type ‘integer‘ as specified by the format specifier ‘%d‘
=> The compiler will proceed once a number is typed in and the ‘Return‘ key is pressed.
The Code At Work
//include your libraries here..
printf(“Enter an integer: \n”); //prompt message
scanf(“%d”, &number); //read message
printf(“The number you entered is: %d”, number);
Enter an integer:
The number you entered is: 25
That’s it, a very simple program to keep things simple for you to understand how interactivity works. Do use the comment form below to add your part..
Other C Programming Articles:
=> Random Numbers in C programming
=> It’s Too Easy To Make This Simple, But Worse, Logical Error In Programming