Consider the following code:
int main(void) { int x=10,y=20,res; switch(x) { case 2: y=10; break; case 4: y=33; break; case 6: y=44; break; case 8: y=55; break; defualt: y=100; break; } printf("y=%d\n",y); return 0; }
it prints:
y=20
The problem here is the switch statement that has a default part but it misspelled (defualt instead of default)
Why it is not a compilation error? in C you can write anything if you put colon (:) after – it declares a goto label
so the result is because there is no default section in this switch
Lets see the code with code highlights:
int main(void) { int x=10,y=20,res; switch(x) { case 2: y=10; break; case 4: y=33; break; case 6: y=44; break; case 8: y=55; break; defualt: y=100; break; } printf("y=%d\n",y); return 0; }
It is easier to notice the difference between the case keyword and the misspelled default
Conclusion:
Always work with editor that support coloring, also use static analysis code tool