ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int c = 0;
    switch (3) {
        default: c += 1;
        case 1: c += 10;
    }
    printf("%d", c);
}
  1. A. 10
  2. B. 11
  3. C. 1
  4. D. 0

Correct answer: B. 11

No case matches 3, so control goes to default, which falls through into case 1. Both additions run, giving 11.

More C Programming questions

Exams that ask this topic