Open In App
Related Articles

C | Loops & Control Structure | Question 7

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

C

#include <stdio.h>
 
int i;
 
int main() {
    if (i) {
        // Do nothing
    } else {
        printf("Else");
    }
    return 0;
}

                    

What is correct about the above program?

(A)

if block is executed.

(B)

else block is executed.

(C)

It is unpredictable as i is not initialized.

(D)

Error: misplaced else



Answer: (B)

Explanation:

Since i is defined globally, it is initialized with default value 0. The Else block is executed as the expression within if evaluates to FALSE. . Therefore, the else block gets executed.



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