struct
student

{
char
name[
10
];
long
sno;
char
sex;
float
score[
4
];
}
;


main()

{
struct
student a[
1
];

long
sno ;
char
name[
10
];
float
score[
4
];
char
sex ;

printf(
"
\n\n%d\n
"
,
sizeof
(a));
printf(
"
%d\n
"
,
sizeof
(score)
+
sizeof
(sex)
+
sizeof
(name)
+
sizeof
(sno));

}
输出的都是 31
typedef union student


{char name[10];
long sno;
char sex;
float score[4];
} Stu ;


main()


{ Stu a[1];

long sno ;
char name[10];
float score[4];
char sex ;

printf("\n\n%d\n",sizeof(a));
printf("%d\n",sizeof(score)+sizeof(sex)+sizeof(name)+sizeof(sno));

}输出的为16,31,
结构和联合有下列区别:
1. 结构和联合都是由多个不同的数据类型成员组成, 但在任何同一时刻, 联合转只存放了一个被选中的成员, 而结构的所有成员都存在。
2. 对于联合的不同成员赋值, 将会对其它成员重写, 原来成员的值就不存在了, 而对于结构的不同成员赋值是互不影响的。