We use cases with switch. But here the cases are inside the default case, so it should require one more switch. But the code doesn't give any compile time errors.
#include<iostream>
int main()
{
int num=4;
while (num)
{
switch(num)
{
default:
case 1:
std::cout<<"Executing "<<num<<"\n";
case 2:
case 3:
break;
}
num--;
}
return 0;
}
Moreover the output is Executing 4 and then Executing 1. According to me the output should be Executing 1 because each time default is being entered. It will enter case 1 when value is 1. But first please explain how this is compiling, because according to me there should be a nested switch.