線形リストを構成するにはmallocでメモリを確保していく方法ですが以下の2つのコードの意味の違いはあるのでしょうか?
C
1struct list { 2 int data; 3 struct list *next; 4}; 5 6struct list node; 7struct list *p = &node;
と
C
1struct list { 2 int data; 3 struct list *next; 4}; 5 6struct list *p; 7p = malloc(sizeof(struct list));
考えれる違いとしては
前者の方は変数nodeとアドレスが結び付けられていますが後者はmallocなので確保したデータのアドレスと結びつく変数はない。
差異はあるのでしょうか?
回答3件
あなたの回答
tips
プレビュー