ProgrammingHardProduct-company MCQ pattern

Assume 32-bit int and two's complement. What is printed?

Assume 32-bit int and two's complement. What is printed?
int x = 5;
int y = ~x + 1;
printf("%d", y);
  1. A. -6
  2. B. 5
  3. C. -5
  4. D. 6

Correct answer: C. -5

~x flips every bit of 5 (0...0101), giving two's-complement -6 (0...1010 is -6's bit pattern). Adding 1 to -6 gives -5. This is exactly the two's-complement identity -x == ~x + 1, so y = -5 = -x.

More C Programming questions

Exams that ask this topic