【发布时间】:2015-05-06 00:44:32
【问题描述】:
这是我为构建链表而尝试完成的代码中的一个 sn-p。出于某种原因,我在尝试编译代码时不断收到错误“错误:预期的';',标识符或'('在'struct'之前”。有人可以帮助我。
struct node;
struct node* buildList(int x);
void push(struct node** headRef, int data);
int findLen(struct node** headRef);
struct node{
int data;
struct node* next;
}
struct node* buildList(int x){
struct node* head = NULL;
head = malloc(sizeof(struct node));
head->data = x;
head->next = NULL;
return head;
}
【问题讨论】:
-
只是在你的结构末尾缺少一个分号,
struct node { ..... }; -
好的,所以在 C 语言中,你必须在每个结构的末尾加上分号?
-
是的。有一些人为的反例。
-
如果这个问题是关于C的,请去掉C++标签。反之亦然。
-
@dfeuer,同样的问题也可能出现在 C 或 C++ 中。我不完全理解您的投诉。
标签: c++ c data-structures linked-list nodes