What you're doing is sort of illegal and has undefined output, which is why it's hard to understand.
You can't modify a variable (p) and read it multiple times in the same instruction because the compiler is free to rearrange the order of those writes/reads however it sees fit.