ProgrammingModerateWipro · Capgemini pattern

What is printed?

What is printed?
int x = 2;
switch (x) {
    case 1: printf("A");
    case 2: printf("B");
    case 3: printf("C"); break;
    default: printf("D");
}
  1. A. BCD
  2. B. B
  3. C. ABC
  4. D. BC

Correct answer: D. BC

Control jumps to case 2 and, without a break, falls through into case 3, printing B then C; the break there stops it before default. Only the matched case and those after it run.

More C Programming questions

Exams that ask this topic