问题 单项选择题

若有下面的说明和定义:
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

答案

参考答案:A

解析: 结构体变量所占内存长度是各成员所占内存长度之和,而共用体变量所占内存长度等于最长成员的长度。本题中,struct test结构体类型共有4个成员,其中int型变量占用2个字节,char型变量占用1个字节,float型变量占用4个字节,共用体变量占用5个字节,共用2+1 +4+5=12个字节。

单项选择题 A1型题
名词解释