結構體 指標 陣列

2022-02-05 22:53:52 字數 886 閱讀 8521

若我們用[0x9999]來標記記憶體位址,則 *[0x9999]表示該位址記憶體中儲存的數值

變數int a;

a *[0x9999] 1

&a [0x9999]

指標int* a;

a *[0x8888] [0x9999]

*a *(*[0x8888]) *[0x9999] 1

&a [0x8888]

結構體變數

struct mystruct

s;s *[0x9991] 1

&s [0x9991]

s.a *[0x9991] 1

&s.a [0x9991]

結構體指標變數

struct mystruct

;struct mystruct* s;

s *[0x8888] [0x9999]

*s *(*[0x8888]) *[0x9999] 1

&s [0x8888]

s->a *(*[0x8888]) *[0x9999] 1

&s->a [0x9999]

*s->a none

陣列(很奇怪)

int a;

&a [0x9999]

a [0x9999]

*a *[0x9999] 1

a[0] *[0x9999] 1

&a[0] [0x9999]

結構體陣列(很奇怪)

struct mystruct

;struct mystruct s;

s[0].a *[0x9999] 1

s[0] *[0x9999] 1

&s[0] [0x9999]

s [0x9999]

*s *[0x9999] 1

&s [0x9999]

陣列指標 結構體指標

指向指標結構體 include include int main struct student stu 1 定義struct student型別的變數stu1 struct student p 定義指向struct student型別資料的指標變數p p stu 1 p指向stu1 stu 1.nu...

結構體指標陣列

struct h a 100 b,c 3 d a是乙個結構體陣列,已經有100個節點了。不需要再分配空間了。b是乙個結構體變數,也已經有空間了,就和int b 已經有空間了一樣。c是乙個指標陣列,c也已經有空間了,有3個元素,但是這三個元素是還沒有分配空間的指標,所以要用malloc分別為他們分配記...

結構體指標和結構體陣列

struct ha 100 b,c 3 d 結構體指標其實是乙個指標,它儲存的是指向某個結構體的 位址 所以結構體指標陣列儲存的其實是指向一組結構體的 位址 陣列,它本身並不包含結構體的具體內容 沒有被分配記憶體 所以當用到他們時,要麼重定向,比如 d b 讓d指向b,d儲存的是b的位址,這樣就能通...