码迷,mamicode.com
首页 > 其他好文 > 详细

使用引用交换两个数字

时间:2014-05-18 16:05:54      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   http   

#include <iostream>

using namespace std;

//定义一个函数,用于交换两个变量的值
void swap(int &a, int &b);

void main()
{
	int i = 3, j = 5;

	cout<<"交换前:i="<<i<<" j="<<j<<endl;

	swap(i,j);

	cout<<"交换后:i="<<i<<" j="<<j<<endl;

	system("pause");
}

//定义一个函数,用于交换两个变量的值
void swap(int &a, int &b)
{
	int temp;

	temp = a;
	a = b;
	b = temp;
}


执行结果:

bubuko.com,布布扣

使用引用交换两个数字,布布扣,bubuko.com

使用引用交换两个数字

标签:style   blog   class   code   c   http   

原文地址:http://blog.csdn.net/u010105970/article/details/26000857

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!