+ 1
what is the difference between *++p, ++*p, and *p++
3 Answers
+ 11
The expression ++*p has two operators of same precedence, so compiler looks for assoiativity. 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 assoiativity. Associativity of operators is right to left. Therefore the expression is treated as *(++p).
*p++ : post increment a pointer p
++*p : pre increment the value at p location
*++p : pre increment a pointer p
so,
*p++ is equivalent to *(p++)
++*p is equivalent to ++(*p)
*++p is equivalent to *(++p)
+ 4
*++p is evaluated as *(++p). It increments the value of p before dereferencing it.
++*p is evaluated as ++(*p). It dereferences p, and then increments it.
*p++ is evaluated as *(p++). The value of p is returned to the expression before being incremented, and then p is dereferenced.
http://en.cppreference.com/w/cpp/language/operator_precedence
0
thanku to all of u