I came across this puzzle here. I can’t figure out why NONE is not printed. Any ideas?
#include<stdio.h>
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;
}
defa1ut:is a syntactically valid label, e.g. for agotobut not thedefaultof the switch statement.If you compile with gcc with enough warnings it will point this out:
It’s a good argument for building with warnings cranked up high and aiming for 0 warnings in every build.