ProgrammingHardProduct company OA

What is printed?

What is printed?
int i = 0, c = 0;
while (i < 10 && ++c && i++ % 3 != 2);
printf("%d %d", i, c);
  1. A. 3 2
  2. B. 2 3
  3. C. 3 3
  4. D. 10 10

Correct answer: C. 3 3

Each test increments c and then i (testing the old i). With old i = 0 and 1 the remainder is not 2, so the loop continues; with old i = 2 the test fails, but i has still been incremented to 3. c was incremented on all three tests.

More C Programming questions

Exams that ask this topic