Re: [問題] address operator &

作者: enonrick (EnonRick)   2018-04-22 21:33:21
很多基礎就不打了,只打一些重點
設環境 x86_32
char* a -> pointer to char
int* b -> pointer to int
int c[4] -> array of int
int (*d)[4] -> pointer to an array of int
sizeof(a) = sizeof(b) = 4
sizeof(char) = 1
sizeof(int) = 4
sizeof(c) = 4 * sizeof(int) = 16
sizeof(d) = sizeof(void*) = 4
//設 a = 0x0,b = 0x0 , &c=0x0
a++ 後為0x0 + sizeof(char) = 0x1
b++ 後為0x0 + sizeof(int) = 0x4
c 實質上是 the address of the first element of an array
&c 是 a pointer to [an array of int]
int *p = c 會被隱型轉成 int *p = &c[0]
int *p = &c 因為兩邊型態不同,所以被強制轉成 int*
c = &c = 0x0 只是型態不同
c 是 int *
&c 是 int (*)[4]
作者: zzss2003 (brotherD)   2018-04-23 09:30:00
精闢
作者: KanzakiHAria (神崎・H・アリア)   2018-04-23 11:53:00
這篇其實有講清楚了 原PO還是卡住XD
作者: splasky (splasky)   2018-04-23 12:04:00

Links booklink

Contact Us: admin [ a t ] ucptt.com