ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned n = 3, c = 0;
    unsigned i = n - 1;
    for (; i >= 0 && c < 10; i--)
        c++;
    printf("%u %u", c, i);
}
  1. A. 10 2
  2. B. 3 0
  3. C. 10 4294967289
  4. D. 10 4294967288

Correct answer: D. 10 4294967288

i is unsigned, so i >= 0 is always true, and the loop stops only when c reaches 10. Starting at 2 and decrementing ten times leaves i = 2 - 10 mod 2^32 = 4294967288.

More C Programming questions

Exams that ask this topic