Rad*_*One 0 c arrays pointers character sizeof
char c[] = {'a','b','c'};
int* p = &c[0];
printf("%i\n", sizeof(*p)); //Prints out 4
printf("%i\n", sizeof(*c)); //Prints out 1
Run Code Online (Sandbox Code Playgroud)
我对这部分代码非常困惑.p和c都表示第0个索引处的数组c的地址.但是为什么sizeof(*p)打印4?不应该是1吗?
小智 5
因为p是类型int *,所以*p类型int,在您的实现上显然是4字节宽.
而使用%zu印刷size_t(什么sizeof产生),如果你不想让你的程序来调用未定义的行为.