最近,在学习结构体的时候,一次代码中定义了结构体、并对结构体进行了初始化,但是编译出错了,这是为什么呢?先来看看代码吧!

从书上查找错误,发现结构体数组变量的初始化有两种方式;
1,在定义结构体的同时,在分号前面直接定义变量并初始化;
例;struct Student
{
char name[20];
char num[10];
char sex[4];
} student[2]={************};
2,定义过结构体变量后,以''struct 结构体名(可无) 变量名''来初始化;
例;struct Student
{
char name[20];
char num[10];
char sex[4];
};
struct Student student[2]={*********};
而我的初始化方式并不属于这两种。
浙公网安备 33010602011771号