C | Loops & Control Structure | Question 7
#include <stdio.h> int i; int main() { if (i); else printf("Ëlse"); return 0; } |
chevron_right
filter_none
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.
Recommended Posts:
- C | Loops & Control Structure | Question 1
- C | Loops & Control Structure | Question 9
- C | Loops & Control Structure | Question 2
- C | Loops & Control Structure | Question 3
- C | Loops & Control Structure | Question 4
- C | Loops & Control Structure | Question 5
- C | Loops & Control Structure | Question 16
- C | Loops & Control Structure | Question 18
- C | Loops & Control Structure | Question 17
- C | Loops & Control Structure | Question 6
- C | Loops & Control Structure | Question 19
- C | Loops & Control Structure | Question 20
- C | Loops & Control Structure | Question 10
- C | Loops & Control Structure | Question 21
- C | Loops & Control Structure | Question 8



