结构体数组在定义的同时也可以初始化,例如:structstu{char*name; //姓名intnum; //学号intage; //年龄chargroup; //所在小组floatscore; //成绩}class[5]={{"Liping",5,18,'C',145.0},{"Zhangping",4,19,'A',130.5},{"Hefang",1,18,'A',148.5},{"Chengling",2,17,'F',139.0},{"Wangming",3,17,'B',144.5}};当对数组中全部元素赋值时,也可不给出数组长度,例如:structstu{char*name; //姓名intnum; //学号intage; //年龄chargroup; //所在小组floatscore; //成绩}class[]={{"Liping",5,18,'C',145.0},{"Zhangping",4,19,'A',130.5},{"Hefang",1,18,'A',148.5},{"Chengling",2,17,'F',139.0},{"Wangming",3,17,'B',144.5}};扩展资料:定义结构体数组和定义结构体变量的方式类似,请看下面的例子:structstu{char*name; //姓名intnum; //学号intage; //年龄chargroup; //所在小组floatscore; //成绩}class[5];表示一个班级有5个学生。参考资料:C语音中文网-C语言结构体数组
阅读全文 >