Today just read the book side effects, bloggers think, side effect is actually changing the value of the variable, that is, an assignment operation! But just in the know still made a mistake!! Awkward!!
As you know, the assignment operator in C is a combination from right to left!!
Here is an example of a side effect in assignment:
#include <stdio.h>
int main ()
{
int a = 3;
A + = a = A*a;
printf ("%d\n", a);
return 0;
}
Did you think of the answer? Does anyone think the answer is-3?
The small partner has made the same mistake as the blogger, the positive solution should be this:
A==3
The first step: a*a==9;
Step two: Execute a-= 9; (Note there is an assignment, which is the side effect we're talking about)
Results: a==-6;
Step Three: Execute a + =-6;
Results: a==-12;
So the execution result should be-12; Try it on the machine!
After all, practice is the only standard to test truth!!
C-language side effects!! Don't be careful!