43. What will be the output of following code :
// Assume all header files are included
main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
A. 2
B. 1
C. scanf(“%d”,&i)
D. Runtime Error
View Answer & Explanation
Ans. b
Explanation : Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1.
44. What will be the output of following code :
// Assume all header files are included
main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
A. 1
B. 0
C. -1
D. Runtime Error
View Answer & Explanation
Ans. a
Explanation : before entering into the for loop the checking condition is “evaluated”. Here itevaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).
