I have encountered <<++
and >>++
operators many time in`C++, but I don't understand what they are. What is the specific meaning and use of these operators, and how are they different from right shift and left shift operator?
Asked
Active
Viewed 115 times
1
-
1I'm pretty sure that's just `>>` and `++` operators squished together. There's a famous question where someone wrote a dumb loop condition that resembles that. – Carcigenicate Jun 02 '18 at 17:01
-
1Very related: https://stackoverflow.com/questions/1642028/what-is-the-operator-in-C even though it's different operators, and C. – Carcigenicate Jun 02 '18 at 17:02
-
1Also, your title doesn't match the body. The ones in the body make sense. I don't think the ones in the title could be possible though. Sticky shift key? – Carcigenicate Jun 02 '18 at 17:04
-
Can you please provide a sample code snippet involving `<<++` and `>>++`? – Ṃųỻịgǻňạcểơửṩ Jun 02 '18 at 17:07
2 Answers
1
C++ compilers ignore whitespace unless in certain situations such as string literals.
<<++
and >>++
is really just a bit-shift operatior <<
or >>
, followed by an increment operator ++
.
Consider this code:
a <<++ b
is equivalent toa<<++b
because the spaces are ignored in this context, and then equivalent toa << ++b
(a
left shifted by a pre-incrementedb
)a << (++b)
due to operator precedence. Bit shift operators have lower precedence than incrementation.

Ṃųỻịgǻňạcểơửṩ
- 2,517
- 8
- 22
- 33
-
1That's a weird way to describe it. `a <<++ b` is equivalent to `a<<++b`, but it's not because spaces are ignored. It's more that the tokenizer parses it as `a, <<, ++, b` since it ignores whitespace (it's not that you remove the spaces, it's that the spaces are ignored), which is bound like `a << ( ++ b)` due to operator precedence. – Justin Jun 03 '18 at 05:45
0
There are two separate operators in both cases: left shift (<<
), right shift (>>
) and increment operator (++
).
You can rewrite the following:
a >>++ b
as:
a >> (++b)

joe_chip
- 2,468
- 1
- 12
- 23