typedef union { long i;int k[5];char c; }DATE; struct date { int cat;DATE cow;double dog; }too;typedef union{ long i;int k[5];char c;}DATE;struct date{ int cat;DATE cow;double dog;}too;DATE max;main(){printf("%d",sizeof(struct date)+sizeof(max));}
来源:学生作业帮助网 编辑:作业帮 时间:2024/09/02 20:52:48
typedef union { long i;int k[5];char c; }DATE; struct date { int cat;DATE cow;double dog; }too;typedef union{ long i;int k[5];char c;}DATE;struct date{ int cat;DATE cow;double dog;}too;DATE max;main(){printf("%d",sizeof(struct date)+sizeof(max));}
typedef union { long i;int k[5];char c; }DATE; struct date { int cat;DATE cow;double dog; }too;
typedef union
{
long i;int k[5];char c;
}DATE;
struct date
{
int cat;DATE cow;double dog;
}too;
DATE max;
main()
{
printf("%d",sizeof(struct date)+sizeof(max));
}
求详细解答
typedef union { long i;int k[5];char c; }DATE; struct date { int cat;DATE cow;double dog; }too;typedef union{ long i;int k[5];char c;}DATE;struct date{ int cat;DATE cow;double dog;}too;DATE max;main(){printf("%d",sizeof(struct date)+sizeof(max));}
sizeof(max)是求max类型的大小,max的类型是union结构,在union结构中所有变量共用同一个空间,在这个union中,i占4 个字节,k[5] 占20个字节,c占1个字节,因为是共用同一个空间,所以union 的大小按最大的变量k[5]来算,占20个字节.
在struct date结构中,cat占4个字节,cow占20个字节,dog占8个字节,合起来就是32个字节.
sizeof(struct date)+sizeof(max) 等于20+32 等于52