[C Language] Wrong Question Book (3)

topic:

To facilitate analysis, we paste the question code below:

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;
}

Correct answer:B

Next, draw a picture to analyze the topic:

From the graph analysis, we can see that in the end, puc[0] stores 00000010, puc[1] stores 00101001, puc[2] stores 00000000, and puc[3] stores 00000000. Use hexadecimal The printed result is: 02 29 00 00.

Guess you like

Origin blog.csdn.net/weixin_72357342/article/details/132723325