struct node{
int data;
struct node *next;
};
main(){
struct node a,b,c,d;
struct node *s=&a;
a={10,&b};
b={10,&c};
c={10,&d};
d={10,NULL};
do{
printf("%d %d",(*s).data,(*s).next);
s=*s.next;
}while(*s.next!=NULL);
}
在a = {10,& b}时显示错误;表达式语法错误。请帮助.. 提前谢谢
答案 0 :(得分:4)
在定义时允许使用仅括号括起列表初始化struct变量。使用
struct node a={10,&b};
否则,您必须使用compound literal [在c99
之上和之上
a=(struct node){10,&b};
答案 1 :(得分:3)
立即初始化变量:
struct node a={10,NULL};
然后分配地址:
a.next = &b;
或使用复合文字:
a=( struct node ){10,&b}; //must be using at least C99