In the expression like ++*p
precedence does not play any role at all. In this expression the inner operator applies to p
(*
in this case). The outer operator (++
) applies to the result of the inner operator.
If you swap them around to obtain *++p
, then ++
will apply to p
, while *
will apply to the result of ++p
.
Every time you have a bunch of unary/postfix operators sitting together on the same side of the operand, they apply in the inside-out order.
For a right-hand side example, in p++[i]
operator ++
applies to p
and [i]
applies to the result of p++
. Meanwhile, in p[i]++
operator [i]
applies to p
and ++
applies to the result of p[i]
.
Precedence begins to play its role in "ambiguous" cases like:
Unary/postfix operator vs. binary operator, e.g.
*p + 2
In the above case unary *
has higher precedence than binary +
, resulting in (*p) + 2
.
p->i / 5
Here postfix ->
has higher precedence than binary /
, resulting in (p->i) / 5
.
And in general unary/postfix operators have higher precedence than binary operators.
Unary vs. postfix operator, i.e. operators on both sides of the operand, e.g.
*p++
In the above case postfix ++
has greater precedence than unary *
, resulting in *(p++)
.
&p->i
Here postfix ->
has greater precedence than unary &
, resulting in &(p->i)
.
And in general postfix operators have higher precedence than unary operators.
Various more "exotic" cases like ?:
operator...