memory allocation for structures elements

前端 未结 7 1174
故里飘歌
故里飘歌 2021-01-19 05:14

Hi I am having difficulties in understanding about how the memory is allocated to the structure elements.

For example if i have the below structure and the size of c

7条回答
  •  礼貌的吻别
    2021-01-19 05:56

    to avoid structure padding! #pragma pack ( 1 ) directive can be used for arranging memory for structure members very next to the end of other structure members.

    #pragma pack(1)
    struct temp
    {
    int a;     // size is 4
    int b;     // size is 4
    double s;  // size is 8
    char ch;   //size is 1
    };
    

    size of structure would be:17

提交回复
热议问题