0
The default case must appear at the end of the switch. It's wrong
i am new .but i think it's wrong in the feed.
5 Respostas
+ 7
default case works when all the cases won't work. Hence, it must be placed at last
+ 2
If you place the default case first then it will only evaluate that. Example's Below.
int age = 30;
switch(age)
{
default:
cout << "You not 30?" << endl;
break;
case 30:
cout << "You are 30...." << endl;
break;
}
In the above example the first thing to be processed is the default statement and that result in the case 30 statement not to become evaluated.
//try now at the end
int age = 30;
switch(age)
{
case 30:
cout << "You are 30...." << endl;
break;
default:
cout << "You are not 30?" << endl;
break;
}
In the above example the case 30 statement is processed first this means that the switch has a chance to processes the age variable being 30. In the first example it does not have a chance to process the case 30 statement because default means nothing above me in the switch statement was true, therefore process the code under me.
0
No Zhang, You are wrong
0
it is also work when default in the middle of switch .
https://code.sololearn.com/cLA4KIn97gdv/?ref=app
0
manukyanzoro9@gmail.com