ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int x = 5, y = 9;
int max = y ^ ((x ^ y) & -(x < y));
printf("%d", max);
  1. A. 9
  2. B. 0
  3. C. -1
  4. D. 5

Correct answer: D. 5

x<y is true (1), and -(1) is all-ones (-1 in two's complement), so (x^y)&-1 simplifies to just (x^y). Then max = y^(x^y) = (y^x)^y = x^(y^y) = x^0 = x = 5. So this particular arrangement actually yields the smaller value (x) when x<y, not the larger — a classic trap when memorizing bit-trick templates without re-deriving them.

More C Programming questions

Exams that ask this topic