首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

写一个互换函数,在主程序中调用该函数,来实现实参值的交换

2012-12-25 
写一个交换函数,在主程序中调用该函数,来实现实参值的交换。#includeiostreamusing namespace stdint ma

写一个交换函数,在主程序中调用该函数,来实现实参值的交换。
#include<iostream>
using namespace std;
int main()
{
 void swap(int*x,int*y);
 int a,b;
 int *p_1,*p_2;
 cout<<"请输入两个数:";
 cin>>a>>b;
 cout<<"交换前:";
 cout<<a<<","<<b<<endl;
 p_1=&a;
 p_2=&b;
 swap(p_1,p_2);
 cout<<"交换后:";
 cout<<a<<","<<b<<endl;
 return 0;
}
void swap(int*x,int*y)
{
 int temp;
 temp=*x;
 *x=*y;
 *y=temp;
}

热点排行