C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Find Output of Program (Q.No. 13)
13.
What will be the output of the program if value 25 given to scanf()?
#include<stdio.h>
int main()
{
int i;
printf("%d\n", scanf("%d", &i));
return 0;
}
Answer: Option
Explanation:
The scanf function returns the number of input is given.
printf("%d\n", scanf("%d", &i)); The scanf function returns the value 1(one).
Therefore, the output of the program is '1'.
Discussion:
23 comments Page 2 of 3.
Lavanya said:
1 decade ago
Why the o/p is -1 if we compile it?
Venkatreddy said:
1 decade ago
I didn't understand why it returns 1. Although scanf reads 25?
Rakesh said:
1 decade ago
As scanf returns total number of input is given to it.
Try again it will return 1, as number of input is 1. Try also this,
int i;
i = printf ("rakesh") ;
printf("%d", i);
Output will be "rakesh6".
Try again it will return 1, as number of input is 1. Try also this,
int i;
i = printf ("rakesh") ;
printf("%d", i);
Output will be "rakesh6".
Akshata Vibhute said:
1 decade ago
I agree with your answer @Sundar but as we all know scanf reads the given input. And here its being written with printf statement.
So not able to know how it will come to know that it must read the number of times its read?
So not able to know how it will come to know that it must read the number of times its read?
Ranjith karthick said:
1 decade ago
Am not get clarity please tell any one.
Sowmiyalaxmi said:
9 years ago
Though scanf may get total number of inputs, here the question is &I then how the output will be one. Explain.
Vijay said:
9 years ago
But in GCC it is different.
It returns, how bytes are read?
Example int is 4.
It returns, how bytes are read?
Example int is 4.
Shubham said:
9 years ago
When I compiled this program it returns the value -1? Can anyone explain?
Pranali said:
9 years ago
If scanf() returns number of inputs(I agree) but what about printf()?(what it will return)
Rubini said:
7 years ago
What will be the output of the following statement?
print("%X%x%ci%x",11,10,'s',12); Please explain with answer.
print("%X%x%ci%x",11,10,'s',12); Please explain with answer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers