|
#include<iostream>
int sub(int*,int*); //声明sub函数,并有两个整形的指针参数
int main()
{
using namespace std;
int a=100,b=200;
cout<<"Before,print a and b: "<<a<<" and "<<b<<"\n";
cout<<"Go to sub()..."<<"\n";
sub(&a,&b); //传递整形a和b的地址到sub()
cout<<"After,print a and b: "<<a<<" and "<<b<<"\n";
return 0;
}
int sub(int *x,int *y) //x,y即,a和b的地址,传入函数中
{
int temp;
temp=*x; //将X地址处的值,赋给整形temp
*x=*y; //将y地址处的值,赋给x地址指向的内存
*y=temp; //将整形temp的值,赋给y地址指向的内存
return *x,*y; //返回x地址和y地址处的值
}
注释里这样的理解正确吗???? |
|