阅读背景:

为什么root的值在main函数中打印为0?

来源:互联网 
#include <stdio.h> 
#include <stdlib.h> 

struct nodeTree { 
    int data; 
    struct nodeTree* left; 
    struct nodeTree* right; 
};

struct nodeTree* insertRoot(struct nodeTree** root, int data) { 
    if(!(*root)) { 
        struct nodeTree *temp = malloc(sizeof(struct nodeTree));
        if(!temp) {
            exit(-1);
    } 

        temp->data = data; 
        temp->left = 0; 
        temp->right = 0; 
        (*root) = temp; 
        free(temp); 
        return *root;
    }
}



 int main() { 
    struct nodeTree *root = NULL; 
    root = insertRoot(&root,10);
    printf("%d\n",root->data);
    return 0;
}
#include <stdio.h> 
#include <stdlib.h> 

struc



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: