gpt4 book ai didi

c - C中结构的大小

转载 作者:太空狗 更新时间:2023-10-29 16:19:47 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why isn’t sizeof for a struct equal to the sum of sizeof of each member?

考虑以下 C 代码:

#include <stdio.h>    

struct employee
{
int id;
char name[30];
};

int main()
{
struct employee e1;
printf("%d %d %d", sizeof(e1.id), sizeof(e1.name), sizeof(e1));
return(0);
}

输出是:

4 30 36

为什么结构的大小不等于其各个组件变量大小的总和?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com