ProgrammingHardTCS NQT · Infosys

What is printed?

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

Correct answer: D. 110

Entry at case 'b' falls through into case 'c' before the break, so 10 + 100 = 110.

More C Programming questions

Exams that ask this topic