switch statement cpp code example
Example 1: c++ switch case statement
switch (n)
{
case 1:
break;
case 2:
break;
default:
}
Example 2: how to make a switch case statement in c++
#include <iostream>
using namespace std;
int main(){
int num = 5;
switch(num + 2) {
case 1:
cout << "Case1: Value is: " << num << endl;
case 2:
cout << "Case2: Value is: " << num << endl;
case 3:
cout << "Case3: Value is: " << num << endl;
default:
cout << "Default: Value is: " << num << endl;
}
return 0;
}
Example 3: switch c++
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 4: switch case sinax c++
switch (<espressione>)
{
case <valore costante 1>:
break;
case <valore costante 2>:
break;
...
case <valore costante N>:
break;
default:
break;
}