C’s “Goes To” Operator

Well it isn’t really an operator but this is a nice C code construct I ran into. It doesn’t seem to have any benefit except as a nice way to create a reverse loop:

int count = 100;
while (count-->0) {
        //some work
}

As I said I don’t think I’ll find any performance benefit for using this code snippet. On the other hand it is always fun to see the puzzled face other programmers have the first time they see the code.

5 thoughts on “C’s “Goes To” Operator”

  1. error: invalid operands of types ‘’ and ‘int’ to binary ‘operator 0 )
    count

  2. I don’t get it – why do you think this is an operator?…it is just the decrementing the count variable and testing whether it is greater than 0, so:

    count–; //decrement
    (count > 0) //and test

    (count– > 0) (on one line)

  3. Of course it’s not a real C operator. This just a nice syntax that resembles the limit sign used in mathematics. When you got x–>0 you call it x goes to 0 so this looked to me similar to the same the C code which actually does something very close, so I called it the “goes to operator”.

    Sorry for any misunderstanding it caused.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.