ProgrammingHardTCS NQT · Infosys
Which type reliably holds the sum 1 + 2 + ... + 100000 = 5000050000?
- A. int
- B. unsigned int
- C. uint64_t
- D. uint16_t
Correct answer: C. uint64_t
5000050000 is larger than both 2^31 and 2^32, so int and unsigned int overflow. A uint64_t holds it without wrap.
More C Programming questions
- What is (uint32t)~0u >> 28?
- int g[2][3] = {1, 2, 3, 4}; What is g[1][1] + g[0][2]?
- uint8t a = 200; a = a + a; What is a?
- Which statement about pointer relations in C is well defined?
- How many subsets of {0, 1, 2, 3, 4, 5} contain exactly three elements?
- #define DOUBLE(x) (x + x). What does printf("%d", DOUBLE(2) 3) print?