ProgrammingHardTCS NQT · Infosys

uint8_t m = 0x0F; uint8_t r = ~m; What is r?

  1. A. 0xF0
  2. B. 0x0F
  3. C. -16
  4. D. 0xFF

Correct answer: A. 0xF0

~m is computed on int after promotion, giving -16. Converting -16 to uint8_t is well defined and yields 256 - 16 = 240, which is 0xF0. Printing ~m directly as int would show -16.

More C Programming questions

Exams that ask this topic