Before the line *p++=*++p;
, p
points to the start of the array s
.
The ++p
in the right hand-side of the line will increment p
by one and so it now points to b
. Dereferencing it with *
will give the value b
and so the right hand side evaluates to b
.
In the left hand side, since the post-increment operator is used, the value of p
will not immediately change. Thus, the value b
from the RHS will be set to the same memory location. Because of the post-increment operator, p
will point to the character c
of the array.
Thus, the char array will remain the same after this line and so abcdef
will be printed. p
however will point to the character c
of the array.
Note that the above is valid only since c++17. From en.cppreference.com/w/cpp/language/eval_order: In every simple assignment expression E1=E2 and every compound assignment expression E1@=E2, every value computation and side-effect of E2 is sequenced before every value computation and side effect of E1