C | Loops & Control Structure | Question 5
Predict the output of the below program:
#include <stdio.h> #define EVEN 0 #define ODD 1 int main() { int i = 3; switch (i & 1) { case EVEN: printf("Even"); break; case ODD: printf("Odd"); break; default: printf("Default"); } return 0; } |
chevron_right
filter_none
(A) Even
(B) Odd
(C) Default
(D) Compile-time error
Answer: (B)
Explanation: The expression i & 1 returns 1 if the rightmost bit is set and returns 0 if the rightmost bit is not set. As all odd integers have their rightmost bit set, the control goes to the block labeled ODD.
Recommended Posts:
- C | Loops & Control Structure | Question 8
- C | Loops & Control Structure | Question 15
- C | Loops & Control Structure | Question 13
- C | Loops & Control Structure | Question 12
- C | Loops & Control Structure | Question 10
- C | Loops & Control Structure | Question 14
- C | Loops & Control Structure | Question 2
- C | Loops & Control Structure | Question 3
- C | Loops & Control Structure | Question 11
- C | Loops & Control Structure | Question 4
- C | Loops & Control Structure | Question 6
- C | Loops & Control Structure | Question 7
- C | Loops & Control Structure | Question 9
- C | Loops & Control Structure | Question 16
- C | Loops & Control Structure | Question 17

