What is the output of the below code?
#include<stdio.h> #define FALSE 0 enum days{ Monday = 3, Tuesday = -1, Wednesday, Thursday }; int main() { int new = 0; switch(new) { case Monday: printf("First Day"); break; case Tuesday: printf("Second Day"); break; case Wednesday: printf("Third Day"); break; case Thursday: printf("Fourth Day"); } return FALSE; }
-------------------------------------------------------------------------------
enum has been declared in which values has been assigned values for first two elements. Considering this, the elements from third shall be assigned in sequence, which shall be Wednesday = 0, Thursday = 1.
In the main function, a variable new is created with 0 assigned to it. The switch case has expression which is now new which is 0. Each case checks for a constant value and as Wednesday is 0, this case shall be entered and prints "Third Day" as output.
0 Comments