What will be the output of given program?
#include<stdio.h>
void main()
{
int i=1, j=-1;
if((printf("%d", i)) < (printf("%d", j)))
printf("%d", i);
else
printf("%d", j);
}
#include<stdio.h>
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
B. 1 -1 -1
C. 1
D. -1
E. complier error
Answer: Option A
Solution (By Examveda Team)
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.
3> So if statement will execute. And answer is 1 -1 1.
in if statement there are 2 printf()
it will work like
printf("%d",i) will return 1 but print 1
printf("%d",j) will return 2 but print -1
if (1
Please explain as early as possible I cannot understand this