First of all, do not be blindfolded, if so, basically compiled but:
int i=1; int b=i+++++i;printf ("%d%d\n", B, i);
MinGW Error: Error:lvalue required as increment operand (as if to say, + + missing left value, where the + + is the third fourth Plus on the title)
VC2010 Error: Error C2105: ' + + ' needs L-value
--------------------------------------------------------------------------
The correct face question should be this:
int i=1; int b=i++ + + +i;printf ("%d%d\n", B, i);
I did not do the compiler, can only learn from the previous knowledge to guess:
As a precondition, there are three expressions in this statement, namely i++ (EXP1), ++i (EXP3), Exp+exp3 = Exp2
1. Remember that before the IF statement has more than one condition, turn on the optimization switch, once the first condition is established, the following conditions may not be evaluated, which means that the compiler parses the expression from left to right.
2. EXP1 = i++ to execute after the current entire statement has been executed. If the sentence has more than one function or contains multiple expressions, you should wait for all of the expressions to be evaluated before executing the + + operation.
3. The expression i++ (EXP1) in this line, and ++i (EXP3), use the same I, so if one of the expressions evaluates to the value of another expression before the end of the entire statement.
Synthesis above analysis: first executes ++i (EXP3), executes after i=2; Then execute B = exp1 + Exp3 = i + i = 2 + 2 = 4; Last execution exp1 = i++ = 2+1 = 3
Results: The results of MinGW and VC2010 were 4, 3, and I was all right. Remember two: the expression is executed from left to right, and multiple expressions share a variable interaction ( rather than a closed calculation after each expression is split). There is always only one I in memory, and the compiler should not take the liberty of adding locks, or more copies of memory, if the intended effect, should be the programmer to do this work, the compiler should not someone else).
I didn't do it myself. Compilers are being bullied, from a perverted i++ problem guessing compiler behavior (the expression is scanned from left to right, the same variable affects each other)