Why is my union's size bigger than I expected?

前端 未结 5 1688
滥情空心
滥情空心 2021-01-18 06:13

When I print the size of a union like this:

union u {
  char c[5];
  int i;
} un;

using this:

int _tmain(int argc, _TCHAR*          


        
5条回答
  •  一生所求
    2021-01-18 06:35

    Thanks for your suggestions. I tried this with a lots of examples and looks that union size is equivalent to (size of max element)+ padding(depending upon the size of highest datatype used).

提交回复
热议问题