in C Plus Plus by
What are the Differences between ++*p, *p++ and *++p?

1 Answer

0 votes
by

1) Precedence of prefix ++ and * is same. Associativity of both is right to left. 
2) Precedence of postfix ++ is higher than both * and prefix ++. Associativity of postfix ++ is left to right.

The expression ++*p has two operators of same precedence, so compiler looks for associativity. Associativity of operators is right to left. Therefore the expression is treated as ++(*p)

The expression *p++ is treated as *(p++) as the precedence of postfix ++ is higher than *. 

The expression *++p has two operators of same precedence, so compiler looks for associativity. Associativity of operators is right to left. Therefore the expression is treated as *(++p)

...