#include <iostream>
#include <cstring>
//#define BYTE char
//传递引用
void swapr(int & a,int & b);
//传递指针
void swapp(int * a,int * b);
//按值传递
void swapv(int a,int b);
int main()
{
using namespace std;
int a=3,b=4;
swapr(a,b);
cout <<a <<"|" <<b<<endl;
swapp(&a,&b);
cout <<a <<"|" <<b<<endl;
swapv(a,b);
cout <<a <<"|" <<b<<endl;
}
void swapr(int & a,int & b)
{
int temp=a;
a=b;
b= temp;
}
void swapp(int * a,int * b)
{
int temp =*a;
*a=*b;
*b=temp;
}
void swapv(int a,int b)
{
int temp=a;
a=b;
b=temp;
}
/*------------------demo 2---------------------------------*/
double swapr(double a);
double swapp(double &a);
using namespace std;
int main()
{
double a=3.0;
cout <<swapr(a) <<endl;
cout << a <<endl;
cout <<swapp(a)<<endl;
cout << a <<endl;
}
double swapr(double a)
{
a *=a*a;
return a;
}
double swapp(double &ra)
{
ra *=ra*ra;
return ra;
}