Precedence and postfix ++

closed account (EwCjE3v7)
What I don't get here is that the postfix ++ has greater precedence than the dereference operator, right?

 
  cout << *pbeg++ << endl; // pbeg is a iterator to a vector 


Wht this does is, that it prints out the value that pbeg points to and than increments it, why I don't get is that isn't the postfix ++ higher than the dereference operator?

I think it does that because it's first increments pbeg and returns the value previous value/address to the dereference operator
precedence is not about what happens first, it is about where to put the parentheses.

Precedence rules dictate that cout << * pbeg ++ << endl is parsed as ( ( cout << ( * ( pbeg ++ ) ) ) << endl ) or, in tree form
        pbeg 
          |
         ++(postfix)
          |
cout      * (unary)
    \    /
      <<   endl
       \  /
        <<     


this means that the value returned from pbeg++ is passed into the unary * as the input. The value returned from pbeg++ is, by definition of postincrement, the old value of pbeg, from before the increment.

closed account (EwCjE3v7)
Thank you so much, that clears so much.
Topic archived. No new replies allowed.