【发布时间】:2021-01-29 07:29:57
【问题描述】:
我正在C 中练习链接列表。我的目标是我想使用 main 之外的函数删除一个节点。
我实现这个目标的计划是在不清除/删除/释放头指针的情况下访问下一个指针,但我得到一个错误:
“[错误] 请求成员 'nextptr' 不是结构或联合”
代码:
void del(struct node **head) {
struct node *temp = *head;
//this is what I believe is wrong, i need to access nextptr of head
*head->nextptr = temp->nextptr->nextptr;
free(temp->nextptr);
temp->nextptr = NULL;
【问题讨论】:
-
或许
(*head)->nextptr? -
它修复了它,但为什么呢?
-
@DasFalscheGewinn 因为operator precedence。顺便说一句:
temp->nextptr->nextptr;看起来很可疑,如果temp->nextptr是NULL你会遇到麻烦
标签: c data-structures linked-list