Skip to content
Related Articles
Open in App
Not now

Related Articles

C | Loops & Control Structure | Question 5

Improve Article
Save Article
Like Article
  • Difficulty Level : Medium
  • Last Updated : 12 Jan, 2013
Improve Article
Save Article
Like Article

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;
}


(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.

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!