ProgrammingHardGATE CS · Campus placements
int x = 12; x = x ^ (x >> 2); What is x?
- A. 10
- B. 6
- C. 12
- D. 15
Correct answer: D. 15
x >> 2 is 3 and 12 XOR 3 = 1100 XOR 0011 = 1111 = 15. Shifting by two rather than one moves the bits further, so the result differs from a Gray code step.
More C Programming questions
- Six people stand in a circle numbered 1 to 6; starting from 1, every second person is removed until one remains. Which number survives?…
- Seven people stand in a circle numbered 1 to 7. Starting from person 1, every third person is removed until one remains. Which number…
- unsigned char a = 200, b = 100; unsigned char c = a + b; printf("%d", c); What is printed?
- In C99 and later, what are the values of (-7) / 2 and (-7) % 2?
- The modular inverse of 3 modulo 1000000007 is which value?
- Which expression is correct for (a b) % MOD with MOD = 1000000007 and 0 <= a, b < MOD, to avoid overflow in C?