ProgrammingVery hardProduct company OA

On a two's-complement machine, what is printed?

On a two's-complement machine, what is printed?
int x = 5;
printf("%d %d", -~x, ~-x);
  1. A. 5 5
  2. B. 6 4
  3. C. 4 6
  4. D. 6 6

Correct answer: B. 6 4

In two's complement ~y = −y − 1. So −~x = −(−x − 1) = x + 1 = 6, and ~−x = x − 1 = 4. The operators apply right to left, innermost first.

More C Programming questions

Exams that ask this topic