ProgrammingHard

int x = 16; printf("%d", x >> 2 ^ 3); What is printed?

  1. A. 4
  2. B. 7
  3. C. 1
  4. D. 12

Correct answer: B. 7

>> has higher precedence than ^, so the expression is (16 >> 2) ^ 3 = 4 ^ 3 = 100 ^ 011 = 111 = 7. 4 forgets the XOR, and 1 treats ^ as subtraction (4 - 3).

More C Programming questions

Exams that ask this topic