[C/en] Added tidbit about fall-though in switch statements.

Another pitfall, as not all languages have fall-through in switches.
This commit is contained in:
Alex Luehm 2015-10-28 17:45:31 -05:00
parent 927ac9c3e8
commit 3b1940b9cc

View File

@ -318,6 +318,12 @@ int main (int argc, char** argv)
case 1:
printf("Huh, 'a' equals 1!\n");
break;
// Be careful - without a "break", execution continues until the
// next "break" is reached.
case 3:
case 4:
printf("Look at that.. 'a' is either 3, or 4\n");
break;
default:
// if `some_integral_expression` didn't match any of the labels
fputs("error!\n", stderr);