关于指针

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 = &ii;
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

 

posted on 2015-06-01 19:57  阳台  阅读(164)  评论(0编辑  收藏  举报

导航