Switch and Jump Statements Interview Questions: C Model Answers and Output Traces
Prepare for C control-flow interviews with precise definitions, a complete score trace, common switch traps and a practical multi-loop goto example.
KnowledgeGate Team
Exam prep & CS education

Interviewers test these statements by asking where control enters, where it leaves, and what output follows when cases fall through. In the sequence, {1, 2, 0, 7, 3, 9, 1}, the trace reaches 52 and never processes the final 1. Definitions, exact paths, and a controlled multi-loop example expose the distinctions behind those answers. Employers may combine definitions, output prediction, debugging and design judgement.
What do switch and jump statements actually control?
What is a switch statement in C?
A switch evaluates its controlling expression once, compares the value with integral constant case labels, and transfers control to the matching label. If none matches, it reaches default when present. Statements then run in source order until the switch ends or a transfer changes the path.
The four jump statements have distinct jobs:
breakexits the nearest enclosing loop orswitch.continuestarts the next iteration of the nearest enclosing loop.returnends the current function and may supply its result.gototransfers control to a named label within the same function.
The mental model is: switch chooses an entry point, while a jump chooses an exit or destination. A matching case does not exit automatically, and cases are not independent blocks.
Which expressions and labels are legal in a C switch?
Can C switch on a string or floating-point value? No. After integer promotions, the expression must have an integer or enumeration type. enum Mode { READ = 1, WRITE = 2 }; enum Mode mode = WRITE; is valid, and switch (mode) enters case WRITE:. Both double rate = 2.0; switch (rate) and switch (name) where name is a char * are invalid; use string comparisons.
Can a variable be used after case? Each label must be a unique integer constant expression after conversion. enum { LIMIT = 2 }; case LIMIT: is valid. int limit = 2; case limit: and block-scope const int limit = 2; case limit: are invalid; const alone does not create a C integer constant expression.
default is optional and may appear anywhere, though last is usually clearer. Case order does not affect matching, but source order controls fall-through after entry. See Conditionals in C: if, else-if and switch with examples for the broader comparison.
Fully worked output trace: fall-through, break, continue and return
Predict the exact output and explain why the last input is ignored.
int route(const int code[], int n) {
int score = 0;
for (int i = 0; i < n; ++i) {
switch (code[i]) {
case 0:
continue;
case 1:
score += 2;
break;
case 2:
score += 3;
/* intentional fall-through */
case 3:
score += 4;
break;
case 9:
return score;
default:
score -= 1;
}
score += 10;
}
return score;
}
int code[] = {1, 2, 0, 7, 3, 9, 1};
printf("%d\n", route(code, 7));Trace only the executed path:
Index | Value | Exact executed path | Score |
|---|---|---|---|
| 1 |
| 12 |
| 2 |
| 29 |
| 0 |
| 29 |
| 7 |
| 38 |
| 3 |
| 52 |
| 9 |
| 52 |
| 1 | Not visited | 52 |
The exact output is 52. Case 2 deliberately shares case 3's work. break reaches the statement after the switch, continue reaches the for iteration expression, and return goes to the caller.

Why break, continue and return are not interchangeable
What exactly does break exit? At code 1, it leaves the nearest switch, not the for, so score += 10 still runs. In general, it exits only the nearest enclosing loop or switch, never every surrounding construct.
What does continue target inside a switch within a loop? A switch is not a loop. At code 0, continue targets the for, skips score += 10, reaches ++i, and retests. In a while, it reaches the condition test; in a do-while, the bottom condition test.
Does return need a following break? No. At code 9, return score ends route; a following break is unreachable. Only return exits the function.
Is goto always wrong? Trace one controlled multi-loop exit
Can goto be reasonable in C? Structured flow is the default, but a short local jump to one same-function label can express a multi-level exit or centralised cleanup without pretending one break exits several loops.
int grid[3][4] = {
{4, 8, 1, 6},
{3, 5, 9, 2},
{7, 0, 11, 10}
};
int r, c;
for (r = 0; r < 3; ++r) {
for (c = 0; c < 4; ++c) {
if (grid[r][c] == 9) goto found;
}
}
printf("not found\n");
return;
found:
printf("%d %d\n", r, c);The visits are 4, 8, 1, 6, 3, 5, 9. The match at r = 1, c = 2 triggers goto found, leaves both loops, and prints 1 2. A plain break would leave only the inner loop. A helper function that returns on finding 9 can be equally clear. Judge a jump by its locality, destination and ownership, not the slogan “never use goto”.

Switch and jump-statement traps interviewers use
Is every missing
breakan error? No. It causes fall-through, which may be intentional and should be clear.Can two cases have the same value? No. Duplicate values violate C's switch constraints.
Can a runtime variable label a case? No. A case needs an integer constant expression.
Is
defaultcompulsory? No.Can
switchtest strings or floating-point values? No. Use other comparisons.
Is a switch always faster than an if-else chain? No. C defines behaviour, not an O(1) promise. A compiler may use comparisons, a jump table or another translation. Use switch for equality against constant labels, and if or else if for ranges and compound predicates.
For maintainability, brace declarations when cases need separate local names. Mark intentional fall-through per project compiler and style rules; omit dead break statements after unconditional return. Validate the C snippet before predicting output. An invalid case label needs a diagnostic, not a runtime guess.
How fundamentals-first and depth-oriented interviews probe control flow
Prepare in three rungs. Fundamentals: define switch, state what break exits, and whether default is compulsory. Trace: reproduce 0 -> 12 -> 29 -> 29 -> 38 -> 52. Depth: explain why case 0 reaches ++i, why labels must be constant, why switch has no speed guarantee, and when local goto is clearer than nested-loop flags.
Use four passes:
Mark the nearest enclosing loop, switch and function.
Identify the selected case and any fall-through.
Draw each
break,continue,returnorgotodestination.Update values only on the executed path.
The Loops and Iteration Interview Questions and Answers set handles iteration counts and nested-loop termination, while switch questions centre on entry labels, fall-through and jump destinations. Use the four passes above to connect the two topics.
Switch and jump statements in 60 seconds, then the next step
Say this checksum: switch evaluates once to select an entry label; cases need unique integer constant expressions; fall-through follows source order; break exits the nearest loop or switch; continue advances the nearest loop; return exits the function; goto reaches a same-function label.
Without notes, reproduce 52, 0 -> 12 -> 29 -> 29 -> 38 -> 52, skipped index 6, and grid result (r, c) = (1, 2). Use the C Language Course for structured concept-and-code practice, or Placement Preparation & Coding for wider preparation.
Keep learning
Switch and Jump Statements in C: Concepts, Traces and Exam Traps
Learn where switch starts execution and where break, continue, goto, and return send control. Trace a loop example step by step and correct common exam mistakes.
C Switch and Jump Statements MCQs: 10 Solved Questions
Solve 10 C control-flow questions, then check each answer with a direct explanation of case selection, jump statements, fall-through, and loop updates.
Control Flow in C Programming: If-Else, Loops, Switch and Jump Statements with Worked Examples
Learn how C chooses, repeats and redirects execution. Trace common output questions step by step, including do-while, continue, switch fall-through and dangling else.
Loops and Iteration Interview Questions in C: 14 Model Answers with Exact Output Traces
Can you predict a C loop after continue moves an update or unsigned arithmetic crosses zero? Work through 14 interview-ready answers, exact traces and termination checks.





