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

标签 c pointers struct

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

相关文章:

c++ - C/C++ Arrays 多维数组

指向以模板作为参数的函数的 C++ 函数指针

c - 声明链表节点

c++ - 使用 C、C++ 和 C++/CLI 项目解决 LNK2005

c++ - 为什么将 char 数组转换为 int 指针并使用指针写入它会使数据反转?

c++ - 我可以使用 '->' 运算符通过指针访问对象指针吗?

C - 从不同的函数访问结构变量

c - 如何用BST制作交互式程序? C郎

c - 尝试在 do while 循环中嵌套 if 语句时出现未知语法错误

python - 编程语言中 C API 的包装器