c - 我正在使用'->',但输出仍在询问我是否打算使用'->'
问题描述
我正在尝试在 C 中创建单链表的功能,但在访问头节点的下一个节点时遇到问题。
typedef struct node {
struct node *next;
} Node;
int foo(Node **head){
*head = *head->next;
}
当我运行此代码时,我希望它将我的头节点指针的地址更改为下一个节点,但我收到以下错误:
‘*head’ is a pointer; did you mean to use ‘->’?
*head = *head->next;
解决方案
foo 内的行应该是
*head = (*head)->next
因为 '->' 的优先级高于 *
您可以在此处了解有关运算符优先级的更多信息 ( https://en.cppreference.com/w/cpp/language/operator_precedence )
推荐阅读
- reactjs - 如何在onClick上获取li值并动态显示
- javascript - 如何使用 Jquery Mask Plugin 处理现有的双精度值
- ajax - 点击按钮时赛普拉斯抛出 cypress.io chrome-error://chromewebdata/ 错误
- sql - UPDATE/MERGE 必须与每个目标行至多匹配一个源行 Bigquery
- javascript - 使用 JS 获取 CSS 计算宽度的问题
- php - 用最低价格替换 WooCommerce 可变产品价格范围
- lua - 如何使用 BodyGyro 将零件指向玩家?
- gpu - 关于 OpenCL 控制流,其中 if(false) 被读取而不是被跳过,以及一般调试 OpenCL
- google-app-engine - GCP kms 加密环境变量并通过 cloudbuild.yaml 将加密密钥传递给谷歌应用引擎
- javascript - 找到流浪号码