Hi,
The problem is that your right hand side and left hand side actually look at the same memory. so while you modify the right hand side before finishing to read it. Hence the result you see.
You should not write and read the same expression in general.