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
相关产品推荐
相关产品推荐

