种方式:传值,传指针,传引用,然后在MAIN函数中分别调用这三个函数,欧分各自的欧别,并
打印,传入前和传入后变量值的变化*/
/*传值
#include<iostream.h>
void sqrt1(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
};
void main()
{
int x,y;
x=100;
y=200;
sqrt1(x,y)
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}*/
#include<iostream.h>
void sqrt2(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
};
void main()
{
int x,y;
x=100;
y=200;
sqrt2(x,y);
cout<<"x="<<x<<endl<<"y="<<y<<endl;
}*/
//传指针
#include<iostream.h>
void sqrt3(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void main()
{
int x=100;
int y=200;
sqrt3(&x,&y);
cout<<"x="<<x<<endl<<"y="<<y<<endl;