返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int x, y;
  7.     x = 10;
  8.     y = 5;
  9.     int *xPtr, *yPtr;
  10.     xPtr = &x;
  11.     yPtr = &y;
  12.     cout << "[對調前]" << endl;
  13.     cout << " x = :" << *xPtr << endl;
  14.     cout << " y = :" << *yPtr << endl;
  15.     cout << "變數x的地址 :" << xPtr << endl;
  16.     cout << "變數y的地址 :" << yPtr << endl;
  17.     xPtr = &y;
  18.     yPtr = &x;
  19.     cout << "[對調後]" << endl;
  20.     cout << " x = :" << *yPtr << endl;
  21.     cout << " y = :" << *xPtr << endl;
  22.     cout << "變數x的地址 :" << yPtr << endl;
  23.     cout << "變數y的地址 :" << xPtr << endl;
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

返回列表