结构指针需要一些澄清

Har*_*hna 2 c struct pointers list

我对以下代码有疑问,

我有如下功能,

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
 }
Run Code Online (Sandbox Code Playgroud)

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

error #2112: Left operand of '->' has incompatible type 'struct myList * *'
Run Code Online (Sandbox Code Playgroud)

谢谢 :)

mfr*_*kli 7

这里的问题是" - >"运算符比"*"运算符更紧密地绑定.所以你的第一个声明:

// what you have written
*root->link;
Run Code Online (Sandbox Code Playgroud)

正在评估:

// what you're getting - bad
*(root->link);
Run Code Online (Sandbox Code Playgroud)

而不是:

// what you want - good
(*root)->link;
Run Code Online (Sandbox Code Playgroud)

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