function
scanf
In Program P3.3, the statement scanf("%d", &a); causes the computer to wait for the user to type a number. Since a is an integer variable, scanf expects the next item in the data to be an integer or a value (like 3.8, say) that can be converted into an integer but dropping the fractional part. If it is not (for example, if it is a letter or a special character) the program will give an error message such as “Invalid numeric format” and stop.
We say the program will crash. If the data is valid, the number will be stored in the variable a. The statement scanf("%d", &b);
works in a similar manner. The statement consists of:
• The word scanf
• Left and right brackets
• Two items (called arguments) inside the brackets, separated by a comma.