0

Explain the output int main(){ int x=4,y=0; switch(--x) { case 3: y+=x; case 4 : y+=x; default : y++; break ;} printf("%d",y); }

control statement

2nd Jun 2019, 9:34 AM
PRAVEEN R
PRAVEEN R - avatar
8 ответов
+ 2
there is no break statement in case 3 and 4 so the code inside case 4 and default also gets executed. y=7
2nd Jun 2019, 9:45 AM
Farry
Farry - avatar
+ 2
in the switch x becomes 3 and then y gets incremented by x twice and by 1 a single time.
2nd Jun 2019, 9:52 AM
Farry
Farry - avatar
+ 2
no, 3 is added
2nd Jun 2019, 9:55 AM
Farry
Farry - avatar
+ 2
the value of x is being added. not the value of case
2nd Jun 2019, 9:58 AM
Farry
Farry - avatar
+ 1
Thank you very much 😊
2nd Jun 2019, 9:58 AM
PRAVEEN R
PRAVEEN R - avatar
0
Default statement executes we get output 8
2nd Jun 2019, 9:49 AM
PRAVEEN R
PRAVEEN R - avatar
0
In case 4 the value of 4 added to x
2nd Jun 2019, 9:53 AM
PRAVEEN R
PRAVEEN R - avatar
0
In case 3 = 3 In case 4 = 4 In default = 1 Then total. 8
2nd Jun 2019, 9:57 AM
PRAVEEN R
PRAVEEN R - avatar