ProgrammingVery hardGATE CS · Campus placements

uint16_t s = 0; for (int i = 1; i <= 1000; i++) s += i; What is s at the end?

  1. A. 500500
  2. B. 41748
  3. C. 0
  4. D. 65535

Correct answer: B. 41748

Each addition wraps modulo 65536, and the final value equals 500500 mod 65536 = 41748. The loop finishes with a defined unsigned value, not the true sum.

More C Programming questions

Exams that ask this topic