Programming Fundamentals · Interview question

What is fall-through and when is it a bug vs a feature?

A strong answer

When a case body finishes without a break, execution doesn't stop, it falls through into the next case. It's a feature when you deliberately want multiple cases to share a body, like grouping vowels: case 'a': case 'e': case 'i': ... printf("vowel"); break;. It's a bug when you forget the break and end up running two cases' bodies, which is the most common switch mistake in C. Compilers don't warn by default; you need -Wimplicit-fallthrough to catch the unintentional ones. When fall-through is intentional, comment it (/* fall through */) so future readers don't "fix" it.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

The switch Statement

When an if/else chain compares one value against many constants, switch is shorter, faster, and tells the reader exactly what's happening.

More The switch Statement questions

Browse all 472 interview questions