ProgrammingHardGATE CS · Campus placements

uint16_t x = 0x0F00; uint16_t y = x & (uint16_t)(0u - x); What is y?

  1. A. 0x0001
  2. B. 0x00F0
  3. C. 0x0100
  4. D. 0x0F00

Correct answer: C. 0x0100

The lowest set bit of 0x0F00 is bit 8, value 0x0100. The negation is taken as unsigned and then truncated to uint16_t, so the mask keeps only that bit.

More C Programming questions

Exams that ask this topic