8,900 views
0 votes
0 votes
#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;
}

(a) 5 (b) 4 (c) 3 (d) None of these

2 Answers

Best answer
3 votes
3 votes
Answer 5

since case 5 is executed a=6 then as their is no break case 1 also executes so a=5 again

So a=5 is printed since case 5 is satisfied default doesn't execute
selected by

Related questions

0 votes
0 votes
1 answer
1
Desert_Warrior asked May 16, 2016
2,354 views
#include<stdio.h int main() { int a = 5; int b = ++a * a++; printf("%d ",b); return 0; }(a) 25 (b) 30 (c) 36 (d) Undefined Behavior
0 votes
0 votes
1 answer
3
Desert_Warrior asked May 16, 2016
5,199 views
#include<stdio.h int main() { char c=125; c=c+10; printf("%d",c); return 0; }(a) 135 (b) +INF (c) -121 (c) -8
0 votes
0 votes
1 answer
4
Desert_Warrior asked May 16, 2016
1,563 views
#include<stdio.h int main() { int i=10; static int x=i; if(x==i) printf("Equal"); else if(x>i) printf("Greater"); else printf("Lesser"); return 0; }(a) Equal (b) Greater ...