CH8 Pointers
備註
本文為 2021-Fall 學期旁聽台大資管系孔令傑教授開授的 Programming Design 所記錄的課程筆記。課程內容程式碼可以參閱我的 Github repo: C++ Programming-Design-2021-Fall
Basics of pointers
pointer
是一種儲存記憶體位置的變數,Array
也是儲存儲存記憶體位置的一種變數,但Array
存的是一排變數中的第一個變數的記憶體位置。
-
To declare a pointer, use
*
type pointed* pointer name;
-
Exp:
int *ptrInt; 儲存int變數記憶體位置的指標
Pointer assignment
We use the address-of operator &
to obtain a variable’s address(取址)
pointer name = &variable name
Exp:
int a = 5;
int* ptr = &a;