中心思想:交换指针只是px和py发生了改变,即px存储了y的地址,py存储了x的地址,也就是可以通过px访问y,通过py访问x,但是x,y本身的地址不会改变!
#includeusing namespace std; int temp; void swap(int *px,int *py) { temp=*px;*px=*py;*py=temp;} int main() { int x=1,y=2; cout<<"交换前 "<<"x="<

中心思想:交换指针只是px和py发生了改变,即px存储了y的地址,py存储了x的地址,也就是可以通过px访问y,通过py访问x,但是x,y本身的地址不会改变!
#includeusing namespace std; int temp; void swap(int *px,int *py) { temp=*px;*px=*py;*py=temp;} int main() { int x=1,y=2; cout<<"交换前 "<<"x="<