Does Postfix operator really has a higher precedence than prefix?
c, operator-precedence, postfix-operator, prefix-operator
Solution
In your first example , you are comparing `*(pointer dereference)` with `postfix/prefix` operators.
`*(pointer dereference)` in this case, has equal precedence with `++(prefix)` but lower precedence than `++(postfix)`. Also note that prefix ++ and * have Right to Left associativity and ++ postfix has left to right.
Now see `*ptr++`, ++ is postfix so first postfix is evaluated than *, hence its `*(ptr++)`.
Now see `++*ptr`, ++ is prefix, so equal precedence, so associativity will come into picture, and * will be evaluated first (because of right to left nature) and then ++ hence its `++(*ptr)`.
Now in your second example,
`b=a++` -> a++ means that postfix on `a`, so value is assigned first and then incremented, But this is the property of postfix, so `a's` value will go into `b` and then `a` will be incremented.
`c=++a` -> ++a means that prefix on a, so first `a` is incremented and then value of `a` goes into `c`.
This example only shows the property of both the operators. Their functionality is performed on two different operations. To compare their precedence, you have to take an example where both are operated into a single statement.
The example can be
int a=5,b;
b= a+++a;
now here the expression will be a++ + a, not a + ++a, because the precedence of postfix is higher than prefix.
Problem
However It is clearly written in precedence table that postfix operator has higher priority than prefix. But still I have a daubt. I start with following example: ``` *ptr++; // evaluate as *(ptr++); ++*ptr; // evaluate as ++(*ptr); ``` This proves that postfix operator has higher precedence than pre one. Now in following example it doesn't seems true: ``` int a=0,b,c; b=a++; //b=0 ,here it seems ++ has lower priority that is after assignment increment is performed. c=++a; //b=2 ,here it seems ++ has higher priority. ``` In above example, Doesn't it seems postfix operator has lower priority than prefix?