typedef struct nodetype
{
int data;
struct nodetype * left;
struct nodetype * right;
}node;
typedef node * tree;
tree newNode(int data)
{
tree temp;
temp = NULL;
temp = (tree)malloc(sizeof(nodetype));
temp->data = data;
temp->right = NULL;
temp->left = NULL;
return temp;
}
関数newNodeでは、ノードを作成するために、 "temp"にNULL値を割り当てます。これが必要かどうかわかりません。私たちがNULLで初期化しないと、それを初期化しているときにptrをNULLに割り当てる必要がある場合、どういう意味がありますか?ポインタの初期化:初期化されたポインタにNULLを割り当てるタイミングは?
これは初期化ではありません。初期化は、値を宣言する同じステートメント内の値を指定する場合です。 'tree temp = NULL;'。 –