1 #define NULL (void*)0
2
3 struct A
4 {
5 int a;
6 char msgdata[4];
7 };
8
9 main()
10 {
11 struct A *p = NULL;
12 printf("%x/n",p->msgdata);
13 strcpy(p->msgdata,"12");
14 }
--------------------------------------------------
~/project/linux> cc -g -o aa aa.c
aa.c: In function 'main':
aa.c:12: warning: incompatible implicit declaration of built-in function 'printf'
aa.c:13: warning: incompatible implicit declaration of built-in function 'strcpy'
--------------------------------------------------
~/project/linux> ./aa
4
Segmentation fault
p->msgdata不会为空的,p = 0, p->msgdata = 0 + sizeof(int) = 4,汗,大哥太牛逼了,吓着小弟了。
2
3 struct A
4 {
5 int a;
6 char msgdata[4];
7 };
8
9 main()
10 {
11 struct A *p = NULL;
12 printf("%x/n",p->msgdata);
13 strcpy(p->msgdata,"12");
14 }
--------------------------------------------------
~/project/linux> cc -g -o aa aa.c
aa.c: In function 'main':
aa.c:12: warning: incompatible implicit declaration of built-in function 'printf'
aa.c:13: warning: incompatible implicit declaration of built-in function 'strcpy'
--------------------------------------------------
~/project/linux> ./aa
4
Segmentation fault
p->msgdata不会为空的,p = 0, p->msgdata = 0 + sizeof(int) = 4,汗,大哥太牛逼了,吓着小弟了。