1 #include <iostream> 2 using namespace std; 3 4 5 void swap(int& x,int& y) 6 { 7 y = x + y; 8 x = y - x; 9 y = y - x; 10 } 11 12 int _tmain(int argc, _TCHAR* argv[]) 13 { 14 int a = 10, b=20; 15 cout << "before swap: a= "<<a <<" b= "<<b<<endl; 16 17 swap(a,b); 18 cout <<"after swap: a= "<<a << " b= "<<b<<endl; 19 20 return 0; 21 }
时间: 2024-11-05 19:41:55