The right shift operator >> is left shift’s mirror: bits slide toward the low end, and each position shifted halves the value. This question from our C Programming Quiz App is quick if you know that rule — and the wrong options map exactly onto the usual confusions.
The Quiz Question
int a = 6;
printf("%d", a >> 1);
What is printed by this code?
- 12
- 3
- 2
- 6
The Correct Answer: 3
6 in binary is 110. Shift every bit one place right and the lowest bit falls off the end: 011, which is 3. One shift right divides by 2. Verified on gcc 13.3 and Apple clang 21, warning-free:
$ gcc -Wall -Wextra rshift.c && ./a.out 3
6 = 1 1 0 6 >> 1 = 0 1 1 = 3 (low bit discarded)
Why Each Wrong Answer Is Wrong
Why not 12?
12 is the left shift: 6 << 1 doubles to 12. Mixing up the arrow direction is the most common slip — the arrows literally point the direction the bits move: >> pushes them right (smaller), << pushes them left (bigger).
Why not 2?
2 would be 6 ÷ 3 — reading the shift count as a divisor. Like left shift, the count is an exponent: x >> n divides by 2ⁿ, so >> 1 divides by 2, not by the count’s value… and definitely not by 3.
Why not 6?
A shift by 1 always moves something (unless the value is 0). Only x >> 0 leaves the number unchanged.
Two Subtleties Worth Knowing
Odd numbers truncate. The dropped bit is simply gone: 7 >> 1 is 3 (not 3.5, not 4) — we verified this in the same run. Right shift is integer division by two, flooring toward negative infinity for the compilers you’re likely using.
Negative numbers are implementation-defined. The C standard doesn’t say whether >> on a negative signed value copies the sign bit in (arithmetic shift) or feeds in zeros (logical shift). Both gcc 13.3 and clang 21 do the arithmetic version:
printf("%d\n", -7 >> 1); /* -4 on gcc and clang (sign bit copied in) */
Note it’s -4, not -3: arithmetic shift floors, while C’s division truncates toward zero (-7 / 2 is -3). So >> and / 2 genuinely disagree on negative odd numbers — one more reason to do bit tricks on unsigned types, where the behavior is fully defined. For the full family of shift pitfalls, see the left shift post and the 1 << 31 signed-overflow trap.
Frequently Asked Questions
Is right shift the same as dividing by 2?
For non-negative integers, yes: x >> n equals x / 2ⁿ, truncating. For negative signed values the two can differ (-7 >> 1 is -4 on gcc/clang but -7 / 2 is -3), and the shift’s behavior is implementation-defined.
What happens to the bits that fall off in a right shift?
They’re discarded. 7 >> 1 drops the lowest 1-bit and yields 3 — there’s no rounding and no carry.
What fills in from the left when right-shifting?
For unsigned types: zeros, always. For signed negative values it’s implementation-defined — gcc and clang copy the sign bit (arithmetic shift), so negative numbers stay negative.
Related Reading
- Left Shift Operator in C – Why 1 << 3 Is 8
- Bitwise AND in C – Why 2 & 3 Is 2
- Multiply by 4 Using Bitwise Operators
- C Aptitude Questions and Answers
Recommended Books
- The C Programming Language – Kernighan & Ritchie (India) | Amazon.com
- C Programming: A Modern Approach – K.N. King (India) | Amazon.com
This question is #61 in the C Programming Quiz App — 155 questions with explanations covering operators, pointers, memory, and more.
Download on Google Play →