![]() |
VOOZH | about |
Interesting Problems of Switch statement in C/C++
Default:Explanation: In switch, an expression "num+2" where num value is 2 and after addition the expression result is 4. Since there is no case defined with value 4 the default case got executed.
BahubaliExplanation: We can write case statement in any order including the default case. That default case may be first case, last case or in between the any case in the switch case statement. The value of expression "movie << (2 + movie)" is 8.
XYZExplanation: In C, comma is also operator with least precedence. So if x = (a, b); Then x = b Note: Case expression can be macro constant.
GEEKSFORExplanation: It is possible to write label of goto statement in the case of switch case statement. This article is contributed by Mr. Somesh Awasthi.