ProgrammingVery hard

In 32-bit signed int arithmetic, what is the largest n such that the sum 1 + 2 + ... + n does not overflow?

  1. A. 65536
  2. B. 46340
  3. C. 32767
  4. D. 65535

Correct answer: D. 65535

65535 x 65536 / 2 = 2147450880, which fits. For n = 65536 the sum is 2147516416, which exceeds INT_MAX.

More C Programming questions

Exams that ask this topic