What is the '-->' operator in C/C++?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
There is no special --> operator in C or C++. What you are seeing is the postfix decrement operator -- followed immediately by the greater-than operator >, and the expression is parsed according to normal language token rules.
How a-- > b Is Parsed
Consider this code:
This does not mean "arrow." It means:
- compare the current value of
atob, - then decrement
aafter the comparison expression uses the old value.
So if a starts as 10 and b is 5, the comparison uses 10 > 5, which is true, and only afterward does a become 9.
Why It Looks Confusing
The characters happen to look like an arrow when written together:
That visual resemblance is what confuses people. But the compiler sees two separate operators, not one combined token.
Common Loop Pattern
A classic example is a countdown loop:
The loop condition compares the old value of counter against 0, then decrements. That is why the printed values are 4, 3, 2, 1, 0.
Compare With Prefix Decrement
The behavior changes if you use prefix decrement instead:
Now the decrement happens first, and the comparison sees the new value. That difference between postfix and prefix decrement is more important than the visual --> shape.
Do Not Confuse This With ->
C and C++ do have a real arrow-like operator: ->. That one is completely different. It is used to access a member through a pointer.
So:
- '
-->is not a single operator,' - '
->is a real operator.'
Those two ideas are unrelated except for how they look on the page.
Readability Advice
Although counter-- > 0 is valid and common, it can be hard for beginners to parse quickly. If the code is performance-insensitive and clarity matters more, some teams prefer a more explicit form:
The compact version is fine when you understand it, but readability is still a design choice.
Expression Evaluation in Practice
It can help to imagine the postfix form as “use the current value, then subtract one afterward.” A tiny runnable example makes that visible:
This prints 1 and then 2. The comparison used the old value 3, and the decrement happened after that expression was evaluated.
Common Pitfalls
- Thinking
-->is a built-in operator. - Forgetting that postfix decrement uses the old value in the current expression.
- Confusing
a-- > bwith the real pointer-member operator->. - Using the compact form in code where readers may misinterpret it.
- Changing
a-- > bto--a > bwithout realizing the semantics changed.
Summary
- '
-->in C or C++ is not a special operator.' - It is parsed as
--followed by>. - '
a-- > bcompares first and decrements afterward.' - '
--a > bbehaves differently because prefix decrement happens first.' - Do not confuse this pattern with the real
->pointer-member operator.
Related reading
- What algorithm is behind STL's find?
- What algorithms are used in C11 stdsort in different STL implementations?
- What algorithms do popular C compilers use for stdsort and stdstable_sort?
- What are C++ functors and their uses?
- What are POD types in C++?
- What are practical uses for STL's 'partial_sum'?
- What are rvalues, lvalues, xvalues, glvalues, and prvalues?
- What are the correct link options to use stdthread in GCC under linux?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.