ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int i = 0, c = 0;
    do {
        i++;
        if (i % 2) continue;
        c++;
    } while (i < 6);
    printf("%d", c);
}
  1. A. 2
  2. B. 4
  3. C. 6
  4. D. 3

Correct answer: D. 3

continue in a do-while jumps to the condition test, so the odd values of i skip the increment. The even values 2, 4 and 6 are counted, giving 3.

More C Programming questions

Exams that ask this topic