gpt4 book ai didi

c - 结构指针中需要一些说明

转载 作者:行者123 更新时间:2023-12-04 09:45:36 25 4
gpt4 key购买 nike

我对下面的代码有疑问,

我有一个函数如下,

void deleteNode(struct myList ** root)
{
struct myList *temp;
temp = *root;
...//some conditions here
*root = *root->link; //this line gives an error
*root = temp->link; //this doesnt give any error
}

所以这两条线有什么区别,对我来说它看起来是一样的..错误是,

error #2112: Left operand of '->' has incompatible type 'struct myList * *'

谢谢你:)

最佳答案

这里的问题是“->”运算符比“*”运算符绑定(bind)得更紧密。所以你的第一句话:

// what you have written
*root->link;

正在评估:

// what you're getting - bad
*(root->link);

而不是:

// what you want - good
(*root)->link;

由于 root 是指向指针的指针,因此 -> 运算符对其没有任何意义,因此出现错误消息。

关于c - 结构指针中需要一些说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10136196/

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