I think you're looking to understand the difference between a reference and a pointer.
Parameter & * diff
Noah L
1
Reputation point
void f1(int& a) {
a = 1;
}
void f2(int* a) {
*a = 2;
}
void main() {
int x = 0;
f1(x);
std::cout << x << std::endl;
f2(&x);
std::cout << x << std::endl;
}
f1, f2가 결국 main함수의 x 데이터를 바꾸는 같은 동작을 하는데,
실제 둘의 차이는 뭘까요?