Open In App
Related Articles

Algorithms Quiz | SP2 Contest 1 | Question 2

Improve Article
Improve
Save Article
Save
Like Article
Like

Predict the output of the below C program: 

C




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


(A)

2-22

(B)

-22-2

(C)

222

(D)

Compilation Error


Answer: (B)

Explanation:

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 02 Nov, 2022
Like Article
Save Article
Previous
Next
Similar Reads