摘要: 下面一段代码,本意是在子函数中给p分配地址并赋值。但程序在printf("%d\n",*p);时崩溃void test(int *p2){ p2 = (int *)malloc(sizeof(int)); *p2 = 8;}void main(){ int *p1 = NULL; //printf("%d\n",p1); test(p1); //printf("%d\n",p1); printf("%d\n",*p1); free(p);}原因:当main在堆栈中定义了指针p1,函数test也在自己的堆栈中定义了p 阅读全文