Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C | Loops & Control Structure | Question 7

  • Difficulty Level : Basic
  • Last Updated : 15 Jan, 2013

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.

#include <stdio.h>
int i;
int main()
    if (i);
    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. Please note that the empty block is equivalent to a semi-colon(;). So the statements if (i); and if (i) {} are equivalent.

My Personal Notes arrow_drop_up
Recommended Articles
Page :