#include <iostream> using namespace std; void swap(int *x, int *y); void swap_(int *x,int *y); void main() { int a = 4, b = 5; cout <<"++++++++++++++++++++++++++++++++++++++"<<endl; cout <<"a = "<< a << " b = " << b << endl; swap(&a, &b); cout <<"a = "<< a << " b = " << b << endl; cout <<"++++++++++++++++++++++++++++++++++++++"<<endl; // int a = 4, b = 5; swap_(&a, &b); cout << "-------------------------------------"<<endl; cout <<"a = "<< a << " b = " << b << endl; } void swap(int *x, int *y) { cout << x << " "<< y <<endl; int *temp; temp = x; x = y; y = temp; cout << "+++++++++++++++++++++++++++++++++++++"<<endl; cout << "x_ = " << x << " y_ = " << y << endl; cout << "x = " << *x << " y = " << * y << endl; cout <<"++++++++++++++++++++++++++++++++++++++"<<endl; } void swap_(int *x,int *y) { int temp; temp = *x; *x = *y; *y = temp; cout << "-------------------------------------"<<endl; cout << "x_ = " << x << " y_ = " << y << endl; cout << "x = " << *x << " y = " << * y << endl; cout <<"--------------------------------------"<<endl; } // debug后你就知道了。。。。。。 仅供入门。。。