题目:
为了方便分析,我们将题目代码贴在下面:
int main()
{
unsigned char puc[4];
struct tagPIM
{
unsigned char ucPim1;
unsigned char ucData0 : 1;
unsigned char ucData1 : 2;
unsigned char ucData2 : 3;
}*pstPimData;
pstPimData = (struct tagPIM*)puc;
memset(puc,0,4);
pstPimData->ucPim1 = 2;
pstPimData->ucData0 = 3;
pstPimData->ucData1 = 4;
pstPimData->ucData2 = 5;
printf("%02x %02x %02x %02x\n",puc[0], puc[1], puc[2], puc[3]);
return 0;
}
正确答案:B
接下来画图分析一下题目:
由图分析可知,最后puc[0]里存放的是00000010,puc[1]里存放的是00101001,puc[2]里存放的是00000000,puc[3]里存放的是00000000.用16进制打印出的结果即为:02 29 00 00.