In C / C ++, the behavior is undefined because in this expression i changes more than once without an intermediate point in the sequence. read: What is the value of i ++ + i ++?
In a Java behavior course, these kinds of codes are clearly defined. Below is my answer for Java, step by step:
At the beginning of i there is 1 .
j = i++ + i++ + ++i; // first step, post increment j = i++ + i++ + ++i; // ^^^ j = 1 + i++ + ++i; // now, i is 2, and another post increment: j = i++ + i++ + ++i; // ^^^^^^^^^ j = 1 + 2 + ++i; // now, i is 3 and we have a pre increment: j = i++ + i++ + ++i; // ^^^^^^^^^^^^^^^^ j = 1 + 2 + 4; j = 7;
source share