ProgrammingHardProduct company OA

What is printed?

What is printed?
enum { R = 4, W = 2, X = 1 };
int perm = R | X;
perm |= W;
perm &= ~R;
perm ^= X;
printf("%d %d", perm, (perm & W) != 0);
  1. A. 2 1
  2. B. 3 1
  3. C. 2 0
  4. D. 6 1

Correct answer: A. 2 1

R | X = 5 (101). |= W sets bit 1 → 7. &= ~R clears bit 2 → 3. ^= X toggles bit 0 off → 2. Only W is left, so the test prints 1. '3' forgets that XOR toggles a bit that is already set.

More C Programming questions

Exams that ask this topic