ProgrammingVery hard
In 32-bit signed int arithmetic, what is the largest n such that the sum 1 + 2 + ... + n does not overflow?
- A. 65536
- B. 46340
- C. 32767
- 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
- How many integers from 1 to 100 are divisible by 6 or by 9?
- With 32-bit unsigned int, what is 65536u 65536u?
- Exponentiation by squaring computes x^1000 with how many multiplications at most, counting squarings and the result multiplications?
- In ASCII, what is 'k' ^ 32 as a character?
- In a 32-bit unsigned int, what is (~0u) >> 28?
- What value does a[i] ^= a[j] leave when i and j refer to the same element?