Question 11
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
for (int i = 0; i < 4; i++) {
switch (i) {
case 1:
printf("one ");
break;
case 2:
printf("two ");
continue;
default:
printf("%d ", i);
}
printf("| ");
}
printf("\n");
return 0;
}
- A 0 | one | two 3 | Correct
- B 0 | one | two | 3 |
- C 0 | one
- D 0 one two 3
Correct Answer: Option A
Inside a switch, break leaves only the switch, so "| " still prints after "one". continue is not used by switch: it goes to the next loop pass, skipping the "| " after "two".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!