ProgrammingHardTCS NQT · Infosys

uint8_t a = 200, b = 250; uint8_t avg = (a + b) / 2; What is avg?

  1. A. 193
  2. B. 97
  3. C. 0
  4. D. 225

Correct answer: D. 225

a + b is computed in int as 450, so the division gives 225, which fits in uint8_t. Wrapping the sum to 8 bits first would wrongly give 97.

More C Programming questions

Exams that ask this topic