- // ConApp引用作为参数两个数的互换.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include "iostream"
- using namespace std;
- void change(int &x, int &y);
- int _tmain(int argc, _TCHAR* argv[])
- {
- int a = 100;
- int b = 90;
- cout << "交换前a:" << a << "\\n";
- cout << "交换前b:" << b << "\\n";
- change(a, b);
- cout << "交换后a:" << a << "\\n";
- cout << "交换后b:" << b << "\\n";
- return 0;
- }
- void change(int &x, int &y)
- {
- int temp;
- temp = x;
- x = y;
- y = temp;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2107201513180.html
来源: http://www.codesnippet.cn/detail/2107201513180.html