Join Regular Classroom : Visit ClassroomTech

scanf() Statement

"scanf()" statement:

“scanf()” is a C library function from the header file “stdio.h”(stdio – standard input output), which allows the programmer to accept input from standard input devices(Keyboard). The taken input is stored in a variable.

Example:

#include<stdio.h>

int main()
{
int a;
printf(“Enter the value of a:”);
scanf(“%d”,&a);// accepts the value of integer variable from user
printf(“The entered value is : %d”,a); // prints the value of variable a
return 0;
}

Enter the value of a: 12
The entered value is : 12

“scanf()” function returns the total number of input taken, which is an integer value.

Let’s see an example –

#include<stdio.h>

int main()
{
int A,B,R;
printf(“Enter two numbers:”);
R = scanf(“%d%d”,&A,&R);
printf(“%d”,R);
return 0;
}

Enter two numbers: 10
12
2

Explanation : In the code we have taken two inputs through “scanf()” function, for integer variables A and B, and that’s why we get an output 2.

Categories
Pages
Recent Posts