+ 2
This code outputs '4' and I wanna know why [explain line by line if you can ; please ] thanks in advance .
int x=1; switch (x) { case1 : x++; case2 : x++; default : x++; } cout<< x ;
4 odpowiedzi
+ 9
There's no "break" keyword. So when the case matches (case 1:), it just proceeds to execute the code under. You will end up with 3 increments, which will give you 4 as a result.
+ 6
And for example if x=2, it will skip the first one, because it is lower than x.
+ 1
You r missing break; statement.
It just increments 1 in each increment statements and outputs 4 .
Technically it is not a switch case program....
0
use break statement and compile it again