#include <iostream>
using namespace std;
int main() {
int x = 10;
int y = 11;
int z = 12;
cout << x++ + --x + y++ - y-- + z;
return 0;
}
The output here is 31
The output usign Visual Studio 2005 is 30
What is wrong !
#include <iostream>
using namespace std;
int main() {
int x = 10;
int y = 11;
int z = 12;
cout << x++ + --x + y++ - y-- + z;
return 0;
}
The output here is 31
The output usign Visual Studio 2005 is 30
What is wrong !
cout << x++ + --x + y++ - y-- + z;
This is undefined behavior.
You cannot access a single variable in a single sequence to both read and write to it multiple times.
As with all undefined behavior, it may work as you expect, it may reformat your hard drive, it may order me a pizza ... or it could start the self destruct sequence for the entire planet. All would be acceptable behavior as what you attempted to do is undefined.