#include
void swap(int a,int b);
int main()
{
int x=8,y=10;
int t=0;
cout<<"x="<<x<<" y="<<y<<endl;
swap(x,y);
cout<<"x="<<x<<" y="<<y<<endl;
cout<<"t in main is :"<<t<<endl;
return 0;
}
void swap(int a,int b)
{
int t;
t=a;
a=b;
b=t;
cout<<"t in swap is: "<<t<<endl;
}
x=8 y=10 输出main函数中xy原值
t in swap is: 8 调用swap函数并输出swap中的t的值
x=8 y=10 输出调用函数后的xy值
t in main is :0 输出main函数的t的值
Press any key to continue