若有下面的说明和定义: struct test { int m1; char m2; float m3; union uu {char ul[5]; int u2[2];} ua; }myaa;

admin2009-01-15  25

问题 若有下面的说明和定义:    struct test    {  int m1;       char m2;       float m3;       union uu  {char ul[5];  int u2[2];}  ua;    }myaa;则sizeof(struct test)的值是(    )。

选项 A、12
B、16
C、14
D、9

答案1

解析 结构体变量所占内存长度是各成员所占内存长度之和,而共用体变量所占内存长度等于最长成员的长度。本题中,struct test结构体类型共有4个成员,其中int型变量占用2个字节,char型变量占用1个字节,float型变量占用4个字节,共用体变量占用5个字节,共用2+1 +4+5=12个字节。
转载请注明原文地址:https://jikaoti.com/ti/zFS0FFFM
0

随机试题
最新回复(0)