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