C++ Switch Case Statement

In this tutorial you will learn about the C++ Switch Case Statement and its application with practical example.

C++ Switch Case Statement

In C++, switch case statement is simplified form of the C++ Nested if else statement , it helps to avoid long chain of if..else if..else statements. A switch case statement evaluates an expression against multiple cases in order to identify the block of code to be executed.

C++ Switch Case Flow Diagram

cpp-switch-case-statement-flowchart

Syntax:-

Example:-

In the above program we have an integer constant dayOfWeek with initial value of 5, and we pass this variable as expression to following switch statement, value of dayOfWeek is tested with multiple cases to identify the block of code to be executed.

When we run the above c++ program, will see the following output –

Output:-

cpp_switch_case_statement

 

In this tutorial we have learn about the C++ Switch Case Statement and its application with practical example. I hope you will like this tutorial.