ProgrammingVery hardGATE CS · Campus placements
uint32_t lo = 3000000000u, hi = 3500000000u; uint32_t mid = (lo + hi) / 2; What is mid?
- A. 3250000000
- B. 2205032704
- C. 1750000000
- D. 1102516352
Correct answer: D. 1102516352
lo + hi = 6500000000 exceeds 2^32, so it wraps to 2205032704 before the division. Halving gives 1102516352, far below both bounds. The safe form lo + (hi - lo) / 2 gives 3250000000.
More C Programming questions
- 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?
- What is the value of (uint64t)1 << 40?