ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int s = 0;
for (int i = 0; i < 5; i++) {
    switch (i) {
        case 1: continue;
        case 3: break;
        default: s += 10;
    }
    s += i;
}
printf("%d", s);
  1. A. 30
  2. B. 40
  3. C. 36
  4. D. 39

Correct answer: D. 39

Inside a switch, break leaves only the switch, but continue goes to the next loop iteration. i = 1 skips everything; i = 3 skips the +10 but still adds 3. Total: (10 + 0) + (10 + 2) + 3 + (10 + 4) = 39.

More C Programming questions

Exams that ask this topic