ProgrammingModerateCapgemini · C

What is printed?

What is printed?
int n = 2, s = 0;
switch (n) {
    case 1: s += 1;
    case 2: s += 2;
    case 3: s += 3; break;
    default: s += 9;
}
printf("%d", s);
  1. A. 2
  2. B. 5
  3. C. 6
  4. D. 9

Correct answer: B. 5

Execution enters at case 2 and falls through to case 3 until the break, adding 2 + 3.

More C Programming questions

Exams that ask this topic