Question 7
Back to Exercise
What does the C standard say about -16 >> 2?
- A It is always 4
- B It is implementation-defined; GCC and Clang give -4 Correct
- C It is a compile error
- D It is always 0
Correct Answer: Option B
Right-shifting a negative value is implementation-defined. Mainstream compilers do an arithmetic shift that copies the sign bit, giving −4. Code that needs portable results should shift unsigned values.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!