C++源码:实现传址参数的实例
// C++源码:实现传址参数的实例 Example for & parametor
#include <iostream>
#include <malloc.h>
using namespace std;
void swap(int&a,int&b);
main()
{
int x,y;
cout<<"\n\n You are wellcome to Tsinghua! Example for & parametor 传址 参数 \n\n";
cout<<"\007"<<"\n\n Please input the vallue of X and Y:"<<flush; // fflush功能:清除读写缓冲区
cin>>x>>y;
cout<<"\nX="<<x<<"\nY="<<y;
swap (x,y);
cout<<"\n\n Now,after SWAP(int&a,int&b), X="<<x<<",Y="<<y << "\n\n";
}
void swap(int& a,int& b)
{
int *temp=new(int);
*temp=b;
b=a;
a=*temp;
delete(temp);
}
赞 (0)