+ 1
Could anyone make me go through this code line by line? I am finding this quite complex. Thank you.
main () { int i = 0, ua = 0, ub = 0, uc = 0, fail = 0; while ( i<=5) { switch ( i ++) { Case 1: Case 2: ++ua; Case 3: Case 4: ++ub; Case 5: ++uc; default: ++fail; } } cout << ua << ub << uc << fail << endl; return 0; }
4 Answers
+ 4
Dipanjan Basu you do not have a break statement after each case so for i value 0 the default case is executed and for i value 1, everything from case 1 is executed till default and for case 2 again everything from there is executed and so on till i = 5.
So all the final updated values of corresponding variables are displayed.
0
I am not getting how ua = 2 ub = 4 uc = 5 and fail = 6 as the condition when met true is incrementing by 1 so all of the values shall increment by 1 so how the diffrentiation?