考虑以下测试程序(键盘执行):
#include <stdio.h>
#include <string.h>
struct camp {
char b[8];
};
int main()
{
struct camp c;
strcpy(c.b, "Hello");
c.b[5] = '\0';
printf("c size: %d\nAddress (amp): %d :: %d\n", sizeof(c), &c, c);
printf("Address of b: %d :: %d\n", &(c.b), c.b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
示例输出:
c size: 8
Address (amp): -1082463628 :: 1819043144
Address of b: -1082463628 :: -1082463628
Run Code Online (Sandbox Code Playgroud)
由(&(c.b)和c.b第二次调用printf)给出的地址相同,struct camp c(第一次调用printf)返回不同的地址.此外,&c与&(c.b)或相同c.b.
究竟发生了什么?