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