I found the below code while googling.
int main()
{
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
printf("NONE\n");
}
return 0;
}
The compiler is not giving an error even if the 'default' is replaced by any other name. It is simply executing the program and exiting the program without printing anything.
Would anyone please tell me why the compiler is not giving an error on default case ? when it is not spelled as 'default'?
It's a normal (goto) label.
You could do this, for example:
int main()
{
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
printf("NONE\n");
}
goto defa1ut;
return 0;
}
If you use GCC, add -Wall
to the options.
Your statement is a valid statement, it declares a label. If you use -Wall, GCC will warn you about the unused label, not more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With