LearnFrenzy
Sign in Take a free test

Bitwise Operators · Bitwise Operators MCQ · Question 7

Right-shifting a negative number in C Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Popular