edited by
355 views
0 votes
0 votes
main()
{
    char check ='a';
    switch(check)
    {
        case 'a'||1:printf("gats");
        case 'b' || 2: printf("quiz");
        break;
        default :printf("Gatesquiz");
    }
}



a)gates

b)gatesquiz

c)gatesquizgatesquiz

d)compiler error

edited by

2 Answers

1 votes
1 votes
ans will be (b)

Reason - since value of check='a', first switch-case 'a'||1 body will be executed and will print 'gates'

now since there is no break statement in the first switch-case, it will jump to body of next switch-case and will print 'quiz'.

Now since here it has break statement, it will come out of switch-body.
0 votes
0 votes
option D

I think it will show compiler error.We get Compiler Time Error

ASCII value of ‘a’ is 97
ASCII value of ‘b’ is 98

'a' || 1: = 1 Since both are non-zero
'b' || 2: = 1 Since both are non-zero

Duplicate case values cause Compile Time Error

That's why I was saying.

plz, let me know if I m wrong...
edited by

No related questions found