I have this code snippet below. Is it correct to describe that sum will be 0 because sum++ will be ignored as assignment of sum += will be adding 0 before increasing the value? Or how is this best described? I mean if I use sum += sum + 1 the result is different.
int sum = 0; for (int i = 0; i < 10; i++) { sum += sum++; } // Sum has end value 0
suminto memory position 1 . Then it loads sum again into memory position 2. It then adds one to memory position 2 and stores the result tosum(without updating memory position 2). It then adds up memory positions 1 and 2 (both still 0) and assigns the result of that to sum so sum is 0 again.sum += ++sum;