- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int x = 10, y = 5;
- int *xPtr,*yPtr;
- xPtr=&x;
- yptr=&y;
- cout<<"對調前 "<<x<<endl;
- cout<<"x=: "<<*xPtr<<endl;
- cout<<"y=: "<<*yPtr<<endl;
- cout<<"變數x的地址"<<xPtr<<endl;
- cout<<"變數y的地址"<<yPtr<<endl;
- xPtr=&y;
- yptr=&x;
- cout<<"對調後 "<<x<<endl;
- cout<<"x=: "<<*xPtr<<endl;
- cout<<"y=: "<<*yPtr<<endl;
- cout<<"變數x的地址"<<xPtr<<endl;
- cout<<"變數y的地址"<<yPtr<<endl;
- system("pause");
- return 0;
- }
複製代碼 |