ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

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

Correct answer: B. 23

Execution jumps to case 2 and then falls through into case 3 because case 2 has no break; the break after case 3 stops before default.

More C Programming questions

Exams that ask this topic