Question 4
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int n = 5;
switch (n) {
default: printf("D ");
case 1: printf("1 ");
break;
case 2: printf("2 ");
}
printf("\n");
return 0;
}
- A D 1 Correct
- B D
- C D 1 2
- D 1
Correct Answer: Option A
No case matches 5, so control jumps to default. It has no break, so it falls through into case 1, which prints 1 and breaks.
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!