Question:
Day code:
int main() {
int a = 8;
int b = 100;
float d;
int c = ++a * a++;
d = b / (--a);
return 0;
}
but for some reason in g ++ the variable с
is 90
, and in msvc it is 81
.
Answer:
The undefined behavior is classic:
int c = ++a * a++;
For C ++ 98:
Writing twice to the variable a
within one sequence point.
For C ++ 11:
Violation of the rules of the order of calculation.
The program is wrong. The compiler can react randomly.