ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int s = 0;
for (int i = 0; i < 6; i++) {
    switch (i % 4) {
        case 0: s += 1;
        case 1: s += 2; break;
        case 2: continue;
        default: s += 10;
    }
    s *= 2;
}
printf("%d", s);
  1. A. 448
  2. B. 224
  3. C. 216
  4. D. 112

Correct answer: B. 224

break leaves only the switch; continue inside a switch belongs to the enclosing loop and skips s *= 2. i = 0: case 0 falls through into case 1 → 3, doubled 6. i = 1: 8 → 16. i = 2: continue, s stays 16 (not doubled). i = 3: default → 26 → 52. i = 4: 55 → 110. i = 5: 112 → 224. 448 doubles on i = 2 as well (treating continue like break); 216 forgets the fall-through from case 0.

More C Programming questions

Exams that ask this topic