小编use*_*451的帖子

假设我们有结构填充,int的大小为4,double的大小为8字节,下面这段代码中结构的大小是多少

任何人都可以告诉我,下面显示的结构的大小是24而不是20.

typedef struct
{
    double d;  // this would be 8 bytes
    char c;   // This should be 4 bytes considering 3 bytes padding
    int a;   // This would be 4 bytes
    float b; // This would be 4 bytes
} abc_t;

main()
{
    abc_t temp;
    printf("The size of struct is %d\n",sizeof(temp));
}
Run Code Online (Sandbox Code Playgroud)

我的假设是当我们考虑填充时结构的大小将是20但是当我运行此代码时,大小打印为24.

c structure padding

5
推荐指数
1
解决办法
73
查看次数

标签 统计

c ×1

padding ×1

structure ×1