You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C语言函数定义报错:expected identifier or '(' before 'void' 求解

问题解决

1. 报错"expected identifier or '(' before 'void'"的修复

你的函数声明犯了返回类型重复定义的错误:同时写了struct node *和void作为返回类型,C语言中一个函数只能指定一个返回类型。从代码逻辑看,你需要返回链表节点指针,所以直接删掉void即可,修正后的函数头为:

struct node * ekleSirali(struct node * r,int x){

2. struct关键字的使用说明

在C语言里,是否需要写struct关键字分两种情况:

  • 如果没有给结构体定义别名:每次声明struct node类型的变量/指针时,必须加上struct关键字,比如你的代码里的struct node *r就是正确写法。
  • 如果用typedef定义了别名:可以省去struct关键字,示例如下:
typedef struct node {
    int x;
    struct node *next;
} Node;

// 之后声明指针就可以直接写Node*
Node * ekleSirali(Node * r,int x){
    // 函数逻辑...
}

内容的提问来源于stack exchange,提问作者risayy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 14:10:28