The Wayback Machine - https://web.archive.org/web/20240314213202/https://www.geeksforgeeks.org/c-loops-control-structure-question-6/
Open In App

C | Loops & Control Structure | Question 6

Like Article
Like
Save Article
Save
Share
Report issue
Report

C




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


Predict the output of above program?

(A)

3

(B)

5

(C)

03

(D)

05



Answer: (C)

Explanation:

The control first goes to the if statement where 0 is printed. The printf(\”0\”) returns the number of characters being printed i.e. 1. The block under if statement gets executed and i is initialized with 3.
Therefore, ’03’ gets printed here.


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


Last Updated : 15 Jan, 2013
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads