二重指针问题(子函数中修改父函数中对象)
问题代码如下:#include <stdlib.h>
typedef struct BiTNode{
int data;
struct BiTree *lchild, *rchild;
}BiTNode, *BiTree;
void CreateBiTree(BiTNode ** biTNode){
*biTNode = (BiTNode *) malloc(sizeof(BiTNode));
(*biTNode)->data = 2;
}
void CreateBiTree_failed(BiTree ** pNode){
*pNode = (BiTree *) malloc(sizeof(Bitree));
// 下面这行报错:Signal: SIGSEGV (Segmentation fault)
(**pNode)->data = 2;
}
int main(){
BiTNode * biTNode;
CreateBiTree(&biTNode);
BiTree * biTree1;
CreateBiTree(&biTree1);
return 0;
}
}