c++ switch case else code example
Example 1: case label in c++
switch(foo) {
case 1:
int i = 42; // i exists all the way to the end of the switch
dostuff(i);
break;
case 2:
dostuff(i*2); // i is *also* in scope here, but is not initialized!
}
Example 2: switch c++
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}