ProgrammingHardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { int x = 2, r = 0; switch (x) { case 1: r += 1; case 2: r += 2; break; case 3: r += 3; default: r += 10; } printf("%d", r); return 0; }

  1. A. 13
  2. B. 3
  3. C. 4
  4. D. 2

Correct answer: D. 2

Without break, execution falls through: x=2 → 2.

More C Programming questions

Exams that ask this topic