ProgrammingHardTCS NQT · Wipro

What is printed?

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

Correct answer: C. 4

The comma operator evaluates i++ and then tests i < 5. The body runs for i = 1 to 4, so n = 4.

More C Programming questions

Exams that ask this topic