My code :-
#include <iostream>
using namespace std;
int main()
{
int b=10;
switch(b)
{
case 40:
cout<<"no";
default:
cout<<"yes";
case 10:
cout<<"done";
}
return 0;
}
I was just experimenting with my code and tried this scenario. I had expected the output to be :-
yesdone
but the output was :-
done
According to me, since the compiler didn't know about the case 10:
when it was reading the default:
statement, it must also execute the stuff inside it.
My question :-
i) When is the default:
case executed by the compiler and hence why is the output coming out to be
done
rather than
yesdone
Thanks for helping.
P.S :- I am using Code::Blocks with GCC compiler.