ProgrammingVery hardProduct company OA

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

Assume 32-bit int, two's complement. What is printed?
int x = 7;
int y = -7;
printf("%d %d", x | y, x ^ y);
  1. A. -1 14
  2. B. -1 -14
  3. C. 7 -14
  4. D. -7 14

Correct answer: B. -1 -14

7 is 0...0111, -7 is 1...1001 (two's complement). OR of these covers every bit that's 1 in either: since -7's upper bits are all 1, the OR is all 1s = -1. XOR: 0111 ^ ...1001 (lower nibble) = ...1110 pattern across all the differing upper bits too, which computes out to -14 exactly (a known identity-free numeric result from direct bit computation).

More C Programming questions

Exams that ask this topic