C语言结构体数组初始化的问题
#include<stdio.h>structLessons{inthaoma;charming;intchengji;};structStudents{intnum;c...
#include<stdio.h>
struct Lessons
{
int haoma;
char ming;
int chengji;
};
struct Students
{
int num;
char name[10];
struct Lessons gaoshu;
struct Lessons Eng;
struct Lessons C;
struct Lessons zhengzhi;
struct Lessons PE;
};
struct Students s[3]={1,"zhao", };
这里gaoshu这些都包含上一个结构体里的成员,怎么初始化? 展开
struct Lessons
{
int haoma;
char ming;
int chengji;
};
struct Students
{
int num;
char name[10];
struct Lessons gaoshu;
struct Lessons Eng;
struct Lessons C;
struct Lessons zhengzhi;
struct Lessons PE;
};
struct Students s[3]={1,"zhao", };
这里gaoshu这些都包含上一个结构体里的成员,怎么初始化? 展开
展开全部
struct Lessons
{
int haoma;
char ming;
int chengji;
};
struct Students
{
int num;
char name[10];
struct Lessons gaoshu;
struct Lessons Eng;
struct Lessons C;
struct Lessons zhengzhi;
struct Lessons PE;
}s1={ 1,"zhang", {100,90,90},{90,90,90},{90,90,90},{90,90,90},{90,90,90} }; //结构体数据,直接用{}括起来就可以
追问
如果s这个数组定义为s[2],那么花括号会不会被系统认定为在定义s数组里的第二个成员?
追答
struct Students
{
int num;
char name[10];
struct Lessons gaoshu;
struct Lessons Eng;
struct Lessons C;
struct Lessons zhengzhi;
struct Lessons PE;
}s[2]={
{ 1,"zhang", {100,90,90},{90,90,90},{90,90,90},{90,90,90},{90,90,90} },
{ 2,"li", {100,90,90},{90,90,90},{90,90,90},{90,90,90},{90,90,90} }
}; //每一组数组用{}括起来,以逗号分隔
上机试一下,就知道了。
展开全部
#include <stdio.h>
typedef struct ss
{
int a;
int b;
}ss;
ss s[3];
int main()
{
s[3] = { 0 }; //方式01 //
//memset(s, 0, sizeof(struct ss) * 3); //方式02 //
printf("\n %d %d %d %d %d %d\t\n", s[0].a, s[0].b, s[1].a, s[1].b, s[2].a, s[2].b);
getchar();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询