gpt4 book ai didi

c - struct node 和 struct node* 之间的 '->' 有什么区别?

转载 作者:太空宇宙 更新时间:2023-11-04 05:25:07 24 4
gpt4 key购买 nike

我是指针的新手,这里有用于合并排序链表的代码。此处它已将虚拟节点声明为 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com