Scanf Returns a value

#include< stdio.h >
main()
{
int b,a;
printf("Enter the Inputs");
a=scanf("%d %d",&a,&b);
printf("\n a value is :\t");
printf("%d",a);
}


OUTPUT


Enter the Inputs
1
2
a value is: 2


what! you amazed with this program?!
In previous post i explained about printf returns a value.
Then i think about that what will be returned by scanf() function.
when i run the program,i got output like this. Go through this program ,definitely
you'll understand the logic.


#include< stdio.h >
main()
{
int a;
printf("Enter the value");
a=scanf("%d",&a);
printf("a value is %d",a);
}


OUTPUT


Enter the value
2
a value is 2


you may get the logic from above programs.

scanf function will return "No of successful inputs getting from user".
for eg:
i=scanf("%d",a);
In this statement scanf function gets one successful input from the user. so it will return 1.

Related Posts