Vidyalelo
C Programming · Q43

Control Structures

Programming · C Programming · question 43

Q43

What will be the output of given program? #include void main() int i=1, j=-1; if((printf("%d", i)) < (printf("%d", j))) printf("%d", i); else printf("%d", j);

A.
1 -1 1
Answer
B.
1 -1 -1
C.
1
D.
-1
E.
complier error

Answer: Option A

Solution

Answer: Option A
Solution:
Here if statement is executed since we know that printf() function return the number of character print.
Here printf("%d", i) return 2 because it print 1 and newline i.e 2.
And, printf("%d', j) return 3 because it print -1 and newline i.e number of character is 3.
Therefore if statement look like if(2<3) yes its true.
So if statement will execute. And answer is 1 -1 1.