某学生的记录描述如下,能将其正确定义并将变量中的“出生日期”赋值为1984年11月11日的是
A.
struct student
{
int number;
char name[20];
char sex;
} s;
struct
{
int year;
int month;
int day;
} birth;
birth.year = 1984;
birth.month = 11;
birth.day = 11;
B.
struct student
{
int number;
char name[20];
char sex;
int year;
int month;
int day;
} s;
year = 1984;
month = 11;
day = 11;
C.
struct student
{
int number;
char name[20];
char sex;
struct
{
int year;
int month;
int day;
} birth;
} s;
s.birth.year = 1984;
s.birth.month = 11;
s.birth.day = 11;
我感觉这四种方式好像都对啊!到底应该怎么赋值?求大神挨个帮我解析一下
再问一下大神:结构体和共用体都不能进行比较操作吗?
比较要用c++的运算符重载,这三个都可以,看题目要求吧,题目要求不一样,结构体就要定义成不一样的,尤其看题目中对于结构体大小的要求,因为结构体存在对齐!
A 使用的是结构体 birth 赋值也正确。。。
B 没有指明,出现数据没有定义。。。
C 使用的结构体嵌套。。