私はstruct
をC言語で読んでいましたが、struct
が初期化される方法を完全に理解していません。 root->right
がNULL
に初期化されていない理由を私は理解できない構造体のメンバを初期化
0
word is NULL
right is not NULL
:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct tnode {
char *word;
int count;
struct tnode *left;
struct tnode *right;
};
int main (void)
{
struct tnode *root;
struct tnode tn1;
root = &tn1;
printf("%d\n", root->count);
if (root->word == NULL)
printf("word is NULL\n");
else
printf("word is not NULL\n");
if (root->right == NULL)
printf("rightis NULL\n");
else
printf("right is not NULL\n");
}
が出力: 以下のコードを考えてみてください。誰かが光を投げてくれますか?
'static struct tnode * root;'を試して、結果を確認してください。 – sjsam