ProgrammingModerateTCS NQT · Accenture

What is printed?

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

Correct answer: D. 4

The loop runs for (i, j) = (0, 10), (2, 9), (4, 8) and (6, 7), and then i = 8 and j = 6 fail the test. So c = 4.

More C Programming questions

Exams that ask this topic