C Puzzle -03
What is the return value of printf() and scanf() functions in C?
scanf() : It returns the number of inputs scanned successfully from keyboard.
Example:
#include <stdio.h>
int main()
{
int a,b,c,n;
printf("Enter the values for a, b and c\n");
n=scanf("%d%d%d",&a,&b,&c); // The variable n receive the return value of scanf
printf("%d",n);
return 0;
}
Output
Enter the values for a, b and c
10
20
30
3
printf() : It returns the number of bytes/characters printed on the screen.
Example
#include <stdio.h>
int main()
{
int n,x;
n=10;
x=printf("%d",n);
printf("\nx=%d bytes",x);
return 0;
}
Output
10
x=2 bytes
Comments
Post a Comment