+ 2

Int x=3; switch(x) { case1: { x+=x;} case3: {x+=x;} case5:{x+=x;} default: {x+=5;} } cout x

what's the output of this question

6th Feb 2018, 7:19 PM
Shridhar Rai
Shridhar Rai - avatar
12 Réponses
+ 2
but the answer is 17
6th Feb 2018, 7:40 PM
Shridhar Rai
Shridhar Rai - avatar
+ 2
and now I understand the answer as break is not there so it execute all the cases below the case 3 also so the output is 17
6th Feb 2018, 7:55 PM
Shridhar Rai
Shridhar Rai - avatar
+ 2
thanks for your help in indirect way
6th Feb 2018, 7:56 PM
Shridhar Rai
Shridhar Rai - avatar
+ 2
and the answer is 17
7th Feb 2018, 12:59 PM
Shridhar Rai
Shridhar Rai - avatar
+ 1
this question is asked when I play challenge in this app
6th Feb 2018, 7:40 PM
Shridhar Rai
Shridhar Rai - avatar
+ 1
no the question is right and the language is c++
6th Feb 2018, 7:45 PM
Shridhar Rai
Shridhar Rai - avatar
+ 1
it's not compulsory
6th Feb 2018, 7:53 PM
Shridhar Rai
Shridhar Rai - avatar
+ 1
yes the program is right you can run on your pc
7th Feb 2018, 12:59 PM
Shridhar Rai
Shridhar Rai - avatar
+ 1
Yes the answer is 17. Compiler execute the case 3. Then case 5 then default because not found break in each case. Or in each case 3 only.
8th Feb 2018, 11:04 AM
Heno ahmed
Heno ahmed - avatar
+ 1
it will be 17 case 3 = 3+3 then x=6 case 5 = 6+6 then x=12 default = 12+5 then x will be "17"
9th Feb 2018, 12:31 PM
Vipul
Vipul - avatar
0
The answer is 11
6th Feb 2018, 10:35 PM
Heno ahmed
Heno ahmed - avatar
0
This program is right
6th Feb 2018, 10:36 PM
Heno ahmed
Heno ahmed - avatar