강의

멘토링

커뮤니티

Inflearn Community Q&A

hodu's profile image
hodu

asked

Following and Learning C++ with Hong Jeong-mo

1.7 Regional scope

강의 마지막 문제 + 마이클피플님 질문관련

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++

Answer 2

1

honglab님의 프로필 이미지
honglab
Instructor

indirection 다음 address-of가 눈에 띄네요~

0

hodu님의 프로필 이미지
hodu
Questioner

그냥 address-of하면 함수의 매개변수인, 포인터변수 x자체의 주소가 찍히니까요!

hodu's profile image
hodu

asked

Ask a question