ProgrammingModerateTCS NQT · Infosys

unsigned char c = 200; int r = (c * c) >> 8; What is r?

  1. A. 40000
  2. B. 156
  3. C. 0
  4. D. 157

Correct answer: B. 156

c promotes to int, so c * c is 40000 with no wraparound. Shifting right by 8 divides by 256 and gives 156. A result of 0 would come from wrongly assuming the product wraps in unsigned char.

More C Programming questions

Exams that ask this topic