ProgrammingVery hardGATE CS · Campus placements

uint32_t lo = 3000000000u, hi = 3500000000u; uint32_t mid = (lo + hi) / 2; What is mid?

  1. A. 3250000000
  2. B. 2205032704
  3. C. 1750000000
  4. 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

Exams that ask this topic