1

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?

Justin
  • 22,898
  • 12
  • 90
  • 138
Shivanshu
  • 644
  • 1
  • 4
  • 16

2 Answers2

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 to
  • a<<++b because the spaces are ignored in this context, and then equivalent to
  • a << ++b (a left shifted by a pre-incremented b)
  • a << (++b) due to operator precedence. Bit shift operators have lower precedence than incrementation.
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,408
  • 1
  • 13
  • 22