Coupon Accepted Successfully!


Nested switch case

C/C++ supports the nesting of switch case. The inner switch can be part of an outer switch. The inner and the outer switch case constants may be the same. No conflict arises even if they are same. The example below demonstrates this concept.

5.16 Write a program to demonstrate the nested switch case statement.


Explanation: The above program aims at identifying whether the input number is zero or an even or an odd number. The first switch case finds out whether the number is zero or non-zero. If a non-zero value is entered, a default statement of first switch case statement is executed, which executes another nested switch case. The nested switch case statement determines whether the number is even or odd and displays the respective messages.

Test Your Skills Now!
Take a Quiz now
Reviewer Name