Skip to content
Related Articles
Open in App
Not now

Related Articles

Algorithms Quiz | SP2 Contest 1 | Question 2

Improve Article
Save Article
  • Last Updated : 02 Nov, 2022
Improve Article
Save Article

Predict the output of the below C program: 


#include <stdio.h>
int main() 
    int i = 2, j = -2;
    if((printf(\"%d\", j)) < (printf(\"%d\", i)))
       printf(\"%d\", i);
       printf(\"%d\", j);
    return 0;








Compilation Error

Answer: (B)


We know that printf() returns the number of character it prints. Hence printf(ā€œ%dā€,j) will return -2 and newline i.e. 3 characters, and printf(ā€œ%dā€, i) will return 2 and newline i.e. 2. Thus if statement will look like (3 > 2) which is false. So the else block is executed followed by the execution of printf() statements within the if condition.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!