Inflearn Community Q&A
강의 마지막 문제 + 마이클피플님 질문관련
Resolved
Written on
·
286
0
1 #include <iostream>
2
3 using namespace std;
4
5 void doSomething(int *x)
6 {
7 *x = 123;
8 cout << *x << " " << &*x << endl; // #2
9 }
10
11 int main()
12 {
13 int x = 0;
14
15 cout << x << " " << &x << endl; // $1
16 doSomething(&x);
17 cout << x << " " << &x << endl; // #3
18
19 return 0;
20 }
이렇게 주소까지 찍어보면
0 0x7ffecc7c2c64
123 0x7ffecc7c2c64
123 0x7ffecc7c2c64
이렇게 값이 나오니까 매개변수를 포인터로 받을 때는 main에 선언된 x를 사용하는거군요
C++





