First of all the output of the first program looks like
x is 1.
x is 2.
x is neither 0, 1 nor 2.
C++ allows to pass the control through all case labels that has no break statement. For example
char c;
std::cin >> c;
switch ( c )
{
case 'y':
case 'Y':
std::cout << "Y was pressed" << std::endl;
break;
case 'n':
case 'N':
std::cout << "N was pressed" << std::endl;
break;
default:
std::cout << "Neither Y nor N was pressed" << std::endl;
break;
}
Some other languages as for example C# do not allow to do this. Nevertheless they require a break statement in any case.:)