本文共 601 字,大约阅读时间需要 2 分钟。
malloc与不使用malloc
1 #include2 #include 3 4 5 typedef struct { 6 int a; 7 char * ch; 8 int aa; 9 }node;10 11 int main()12 {13 int *i = NULL;14 int ii = 10; 15 i = ⅈ16 printf("local %p\n", i); 17 node * aa = (node*)malloc(sizeof(node));18 printf("local %p\n", aa->ch);19 if(aa->ch ==NULL){20 printf("local %p\n", aa->ch);21 } 22 23 node bb; 24 printf("local %p\n", bb.ch);25 free(aa);26 return 0;27 }
root@u18:~/cp/test# ./a.out
local 0x7fffe2aa515clocal (nil)local (nil)local 0x400640
转载地址:http://iuznl.baihongyu.com/