C | Loops & Control Structure | Question 21

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<stdio.h>
int main()
{
    int a = 5;
    switch(a)
    {
    default:
        a = 4;
    case 6:
        a--;
    case 5:
        a = a+1;
    case 1:
        a = a-1;
    }
    printf("%d \n", a);
    return 0;
}

chevron_right


(A) 3
(B) 4
(C) 5
(D) None of these


Answer: (C)

Explanation: There is no break statement, so first a = a + 1 is executed, then a = a-1 is executed.

Quiz of this Question



My Personal Notes arrow_drop_up