Directly Add code
# Include <iostream> using namespace STD; void swap (int * a, int * B) {* a ^ = * B ^ = * a ^ = * B ;} void swap1 (int * a, int * B) {int temp; temp = * A; * A = * B; * B = temp;} void swap2 (int *, int * B) {* A + = * B; * B = * A-* B; * A = * A-* B;} int main () {int A = 1, B = 2; int * m = & A; int * n = & B; swap2 (m, n); cout <A <Endl; cout <B <Endl; return 0 ;}
Swap1 is a common method. Compiling and running under VC is normal, and g ++ is also OK ~~~
Swap2 does not require any intermediate variables, but it may overflow-you know ~~~
The swap version is clever. After three different or complete exchanges, there is no logic problem. The compilation and operation are normal in VC, but the result is incorrect after G ++ ~~~
You can try it ~~~
Why?
Answer: the reason for the compiler ~~~ Unknown ~~~ How can this problem be solved ~~~
PS: it seems that it is indeed a global warming ~~~ :)