1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include "stdafx.h" #include <iostream> using namespace std; int func(int & num) { num = num+3; return num+3; } int main() { int num = 50; int & num2 = num; num2 = func(num); num2++; cout << num2 << endl; // 57 cout << num << endl; // 57 while (1) {} return 0; } | cs |
& 변수는 같은주소 변수를 뜻한다. 주소참조 포인터 변수와는 비슷하지만 다른 용도이다
'2019 > c++' 카테고리의 다른 글
relational data structures & strings (C++ STL) (0) | 2018.03.21 |
---|---|
dynamic allocation of 2-dimension array (0) | 2018.03.20 |
Template classes, operator overloading (0) | 2018.03.18 |
time&chronos (0) | 2018.03.17 |
basic data structures (0) | 2018.03.17 |