C++中利用引用传参

#include <iostream>

using namespace std;

void swap(int &a, int &b)
{
	int temp = a;
	a = b;
	b = temp;
}

int main(void)
{
	int a = 10, b = 20;
	swap(a, b);
	cout <<"a=" << a << endl;
	cout << "b=" << b <<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42386328/article/details/83450054
今日推荐