SCANF():
The scanf function is used to get input from the user. The input
is stored in a variable in a specified format.
Syntax:
The syntax of scanf function is as follows
scanf (format string, &variable1, &variable2, &variable3);
Format String:
The format string is given in double quotes It may consist of different format
Specifiers that indicate the format according to which values will be entered.
Variables: The
variables are used to store the value entered by the user through the keyboard.
Each variable refers to a memory location. The symbol & indicates the memory
location of the variable in which the input is stored It is called the address operator
Getting Single Input.
Examples:
Getting single input:
scanf (“%d”, &a);
The above statement is used to get integers input. The value
entered by the user will be stored in variable “a”.
Getting Multiple input:
Scanf function can be used to input many values at the same
time as follows;
scanf(“%d %d ,&a, &b);
The above statement will get two inputs in a and b respectively.
It is also possible to get different types of input in the same function as
follows
scanf (“%d %f”, &a, &b);
The scanf function is normally used in combination with printf
function. The purpose of using printf function before scanf is to tell the user
that the computer is waiting for input.
Example:
printf(“ Enter your marks”);
scanf(“%d” ,&a);