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