Switch
switch compares a value with several case labels. End each case with break, or execution falls through into the next one. default handles everything else.
Example
int day = 3;
switch (day) {
case 1: printf("Monday\n"); break;
case 2: printf("Tuesday\n"); break;
case 3: printf("Wednesday\n"); break;
default: printf("Other day\n");
}Result
Wednesday
Exercise
Stop the case from falling through.
case 1: printf("a"); ;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.