假设现在有结构体struct student student1, student2//结构体变量名
我能不能先申明,然后再初始化呢,上面是申明,下面再student1 = {};student2 = {}
在编译的时候出现error:expected expression before ‘{’token
不知道为什么,有人能够解释一下其中的原理吗?
代码如下:
#include<stdio.h>
typedef struct weapon{
int price;
int rtk;
char name[20];
struct weapon *next;
}W;
int main()
{
W *head;
W w1,w2,w3;
w1 ={100,200,"ijnjin",NULL};
w2 ={1400,24400,"ifafadfjnjin",NULL};
w3 ={13400,204440,"ifdfsdfsdjnjin",NULL};
head = &w1;
W *p = head;
while(p!=NULL){
printf("the price is %d,the nane is %s,the rtk is %d\n",p->price,p->name,p->rtk);
p = p->next;
}
return 0;
}
慕的地6079101
慕用4063026
精慕门0141219
慕用4063026
成为优秀的人
相关分类