c语言中的结构体

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:43:28
struct date
{ int year ,month,day;};

struct student
{
char name[12];
char sex;
struct date birthday;
float sc[4];
};
在上面的结构体中,struct date 是已经说明过的结构体,若没有说明过,可写成这样
struct student
{
char name[12];
char sex;
struct
{int year;
int month;
int day;
}birthday;
folat sc[4];
};
我要问的是,在这个结构体说明中,能否将它

struct
{int year;
int month;
int day;
}birthday;
改为
struct date
{int year;
int month;
int day;
}birthday或者
struct birthday
{int year;
int month;
int day;
}
改成这俩个正确吗?!

struct date
{int year;
int month;
int day;
}birthday或者
struct birthday
{int year;
int month;
int day;
}
这两个都对,不过第一个定义了结构体类型date和一个date型的结构体birthday。第二个定义了结构体类型birthday。

struct student
{
char name[12];
char sex;
struct
{int year;
int month;
int day;
}birthday;
folat sc[4];
};
只能这样改,否则运行出错

不正确
建议用正常写法 你这样写的不太清晰

struct date
{int year;
int month;
int day;
}birthday或者
struct birthday
{int year;
int month;
int day;
}
是正确的,中间的那个是错误的