ExamVeda
Login
Home
This question belongs to C Program Control Structures
Control Structures
?

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);
}

Answer & Solution
Correct Answer: Option A
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.
Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Deepak Goyal
Deepak Goyal 6 years ago
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
Sanchita Akole
Sanchita Akole 8 years ago
Please explain as early as possible I cannot understand this