ProgrammingModerateHCL · Tech Mahindra pattern

What is printed on a two's-complement machine?

What is printed on a two's-complement machine?
printf("%d", ~5);
  1. A. -5
  2. B. 250
  3. C. 10
  4. D. -6

Correct answer: D. -6

~ flips every bit. In two's complement ~x = -x - 1, so ~5 = -6. 250 is what you would get if only 8 bits were flipped and read as unsigned.

More C Programming questions

Exams that ask this topic