본문 바로가기

언어/C++

5장 1번 - 참조 매개변수 이용해서 swap

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void swap(int &n,int &m){
	int temp;
	temp=n;
	n=m;
	m=temp;
};

int main(int argc, char** argv) {
	
	int a =1;
	int b= 10; 
	cout<< "a 반지름 : " << a;
	cout<< "b 반지름 : " << b;
	 
	cout <<"swap 후 ";
	
	swap(a,b);

	cout<< "a 반지름 : " << a;
	cout<< "b 반지름 : " << b;
	 
	
	return 0;
}