This question already has answers here:
Why can't we initialize members inside a structure?
(6个答案)
4年前关闭。
为什么为以下代码引发此错误。
码:
您可以在声明过程中执行
(6个答案)
4年前关闭。
为什么为以下代码引发此错误。
Error: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
struct node_s *next=NULL;
码:
#include<stdio.h>
#include<stdlib.h>
typedef struct node_s {
int data;
struct node_s *next=NULL;
} node;
最佳答案
您必须删除指针的NULL
初始化。仅在声明处允许初始化。
typedef struct node_s {
int data;
struct node_s *next;
}node;
您可以在声明过程中执行
node a = { .next = NULL };
初始化指针。关于c - 在结构定义= NULL中分配下一个指针,将引发错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31859492/