operator
-->
c++
c

What is the '-->' operator in C/C++?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

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:

cpp
1int a = 10;
2int b = 5;
3
4if (a-- > b) {
5    // ...
6}

This does not mean "arrow." It means:

  1. compare the current value of a to b,
  2. then decrement a after 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:

cpp
counter-- > 0

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:

cpp
1#include <iostream>
2
3int main() {
4    int counter = 5;
5
6    while (counter-- > 0) {
7        std::cout << counter << "\n";
8    }
9}

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:

cpp
1int counter = 5;
2
3while (--counter > 0) {
4    // ...
5}

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.

cpp
1struct Node {
2    int value;
3};
4
5Node n{42};
6Node* p = &n;
7
8std::cout << p->value << "\n";

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:

cpp
1while (counter > 0) {
2    --counter;
3    // ...
4}

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:

cpp
1#include <iostream>
2
3int main() {
4    int x = 3;
5    bool result = x-- > 1;
6
7    std::cout << result << "\n";
8    std::cout << x << "\n";
9}

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-- > b with the real pointer-member operator ->.
  • Using the compact form in code where readers may misinterpret it.
  • Changing a-- > b to --a > b without realizing the semantics changed.

Summary

  • '--> in C or C++ is not a special operator.'
  • It is parsed as -- followed by >.
  • 'a-- > b compares first and decrements afterward.'
  • '--a > b behaves differently because prefix decrement happens first.'
  • Do not confuse this pattern with the real -> pointer-member operator.

Course illustration
Course illustration

All Rights Reserved.