我是指针的新手,这里有用于合并排序链表的代码。此处它已将虚拟节点声明为 struct node dummy;
并且虚拟节点的下一个节点为 NULL,因此我们使用 dummy.next = NULL;
来设置它。
/* Link list node */
struct node
{
int data;
struct node* next;
};
struct node* SortedMerge(struct node* a, struct node* b)
{
/* a dummy first node to hang the result on */
struct node dummy;
/* tail points to the last result node */
struct node* tail = &dummy;
/* so tail->next is the place to add new nodes
to the result. */
dummy.next = NULL;
//Code continues...
}
我知道如果它是 struct node *dummy;
我可以使用它
但我们不能在这里使用它,因为它不是指针节点。
所以我的问题是为什么 dummy->next = NULL
在这里不起作用?
struct node 和 struct node* 有什么区别??
最佳答案
a -> b
是 (*a).b
的简写。
如果 a
不是指针,则 *a
无效,a -> b
也无效。
关于c - struct node 和 struct node* 之间的 '->' 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32754168/