0 Answer
If fun(i+3,i-2), the values of both expressions are first cached in temporary storage and passed as arguments to fun
If fun(i+=3,i-=2), The first assignment is done, the result of the expression is actually i itself, and the final execution is fun(i,i)
Then why distinguish between function arguments evaluated from left to right and from right to left?
the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > in the vc + + environment, according to the operation rules of c + +, the function parameter order is uncertain. Thus, in fun(i+=3, i-=2), the order of execution of i+=3 and i-=2 is indeterminate. Some compilers may execute i+=3 first, others may execute i-=2 first.
Suppose the compiler executes i+=3 and then i-=2, the following process would occur:
1, i+=3 is equivalent to i=i+3, that is, add the value of i to 3, then the value of i is 11.
2, i-=2 is equivalent to i=i-2, that is, subtract 2 from the value of i, and then the value of i is 9.
3, fun(i+=3, i-=2) is equivalent to fun(11, 9), that is, 11 and 9 are passed to the function as arguments.
So if the compiler executes i+=3 and then i-=2, it gets fun(11, 9).
If the compiler executes i-=2 and then i+=3, it gets fun(9, 10).
In summary, the result of the function call fun(i+=3, i-=2) may vary depending on the order in which the compiler evaluates the arguments.
It evaluates the entire assignment statement before passing i as an argument to fun. i is equal to 9, so both arguments are 9
这家伙很懒,什么都没留下...