malloc与不使用malloc
1 #include <stdio.h> 2 #include <stdlib.h> 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 0x7fffe2aa515c
local (nil)
local (nil)
local 0x400640