C++/ํฌ์ธํฐ (Pointers)
[C++] ํฌ์ธํฐ์ ์ ์ธ (Declaring Pointers)
Chan Lee
2023. 12. 19. 18:03
ํฌ์ธํฐ์ ์ ์ธ์ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์กฐ๋ก ์งํ๋ฉ๋๋ค.
variable_type *pointer_name;
asterisk(*)๋ง ์์ด์ง๋ฉด ๋ณ์์ ๋์ผํฉ๋๋ค.
์์
int *int_ptr;
double *double_ptr;
char *char_ptr;
string *string_ptr;
ํ์ง๋ง, ์ค์ํ ๊ฒ์ ์ ์ธ๊ณผ ๋์์ ์ด๊ธฐํ๋ฅผ ํด ์ฃผ์ด์ผ ํฉ๋๋ค.
์ด๊ธฐํ๋ฅผ ํ์ง ์์ผ๋ฉด ํฌ์ธํฐ์ ์ฐ๋ ๊ธฐ ์ฃผ์ ๋ฐ์ดํฐ๊ฐ ๋ค์ด์๊ฒ ๋ฉ๋๋ค.
์ด๊ธฐํ๊น์ง ํ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ๋ฉ๋๋ค.
variable_type *pointer_name {nullptr};
์์
int *int_ptr {};
double *double_ptr {nullptr};
char *char_ptr {nullptr};
string *string_ptr {nullptr};