ProgrammingHardTCS NQT · Infosys
uint32_t a = 4000000000u; uint32_t s = a + a; What is s?
- A. 8000000000
- B. -294967296
- C. 3705032704
- D. 4000000000
Correct answer: C. 3705032704
Unsigned addition is reduced modulo 2^32 (4294967296): 8000000000 - 4294967296 = 3705032704. The result always stays in range, so no undefined behaviour occurs.
More C Programming questions
- uint32t lo = 3000000000u, hi = 3500000000u; uint32t mid = (lo + hi) / 2; What is mid?
- uint32t x = 0u; Which statement about the test (x & (x - 1)) == 0 is correct?
- uint8t x = 0x81; uint8t r = (uint8t)((x >> 1) | (x << 7)); What is r?
- What is the value of 1 << 2 + 3 in C?
- int x = 2; printf("%d", x & 1 == 1); prints what?
- uint32t x = 1u; x <<= 31; x <<= 1; What is x afterwards?