I write this code to switch two values without temp storage and it works well, but when I try to use the same style to do other things, it doesn't work as I expected.
`
#include <iostream>
using namespace std;
int main(){
int i=100,j=200;
//expect swich i and j
i=j+i-(j=i);
cout<<i<<" "<<j<<endl;
//expect j=100 and i=300
i=j+(j=i);
cout<<i<<" "<<j<<endl;
}
result is:
200 100
400 200
so why doesn't the second (j=i)
work?
can we just have a discussion about this situation? no one will maintain such code, including me.