#include<iostream>
#include<iomanip>
using namespace std;
void Change(int &x1,int &y1);
void Change(float &x2,float &y2);
void Change(char &x3,char &y3);
void Change(double &x4,double &y4);
int main()
{
int x1=10,y1=20;
float x2=10.1,y2=20.2;
char x3='a',y3='b';
double x4=10.01,y4=20.02;
Change(x1,y1);
Change(x2,y2);
Change(x3,y3);
Change(x4,y4);
return 0;
}
void Change(int &x,int &y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}
void Change(float &x,float &y)
{
float temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}
void Change(char &x,char &y)
{
char temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}
void Change(double &x,double &y)
{
double temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}
#include<iomanip>
using namespace std;
void Change(int &x1,int &y1);
void Change(float &x2,float &y2);
void Change(char &x3,char &y3);
void Change(double &x4,double &y4);
int main()
{
int x1=10,y1=20;
float x2=10.1,y2=20.2;
char x3='a',y3='b';
double x4=10.01,y4=20.02;
Change(x1,y1);
Change(x2,y2);
Change(x3,y3);
Change(x4,y4);
return 0;
}
void Change(int &x,int &y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}
void Change(float &x,float &y)
{
float temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}
void Change(char &x,char &y)
{
char temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}
void Change(double &x,double &y)
{
double temp;
temp=x;
x=y;
y=temp;
cout<<"传递后:x="<<x<<",y="<<y<<endl;
}