Regarding structure padding in c++

后端 未结 4 428
猫巷女王i
猫巷女王i 2021-01-16 05:50

I use a datastructure in my project and in the context of a paricular structure i have a doubt about strucure padding. First Look at the strucure given below. I use Visual S

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 06:22

    check out this:

    typedef struct myTagDATA_PACK3
    {
        char c;
        double d;
        int i;
    }DATA_PACK3;
    

    it shows 24 bytes. That is: double:8 bytes. int : 4 bytes + (4 bytes padding) = 8 bytes. char: 1 byte + (7 bytes padding) = 8 bytes.


    Total:24 bytes.

提交回复
热议问题