(7070)
두 개의 정수를 바꾸는 함수 rswap 을 만들되 두 파라메터를 pointer 가 아닌 reference 로 한다.
#include <iostream>
using namespace std;
void rswap(int &o, int &t ){
int temp;
temp=o;
o=t;
t=temp;
}
int main(){
int one, two;
cin >> one >> two;
cout << one << " " << two << endl;
rswap(one, two);
cout << one << " " << two << endl;
return 0;
}
'C++ > Basic' 카테고리의 다른 글
구조체 기초 연습 (0) | 2021.01.20 |
---|---|
string 출력 오류 처리 (0) | 2021.01.20 |
string try-catch 오류처리 (0) | 2021.01.20 |
string 읽어들여 공백 없애고 역순으로 출력하기 (0) | 2021.01.20 |