qq_37335168 2022-05-16 08:24 采纳率: 84%
浏览 18
已结题

下面是一个结构体位域,结构体变量的内存大小不应该是8Byte吗,为什么是4Byte?

#include <stdio.h>
struct EIGHT_BYTE
{
    unsigned char ccc1 : 1;
    unsigned int ccc2 : 1;
} eight_byte;

int main(int argc, char const *argv[])
{
    printf("sizeof one_byte is : %lu\n", sizeof(one_byte));
    printf("sizeof two_byte is : %lu\n", sizeof(two_byte));
    printf("sizeof three_byte is : %lu\n", sizeof(three_byte));
    printf("sizeof four_byte is : %lu\n", sizeof(four_byte));
    printf("sizeof eight_byte is : %lu\n", sizeof(eight_byte));
    return 0;

sizeof eight_byte is : 4

  • 写回答

3条回答 默认 最新

  • yun6853992 2022-05-16 08:43
    关注

    我在vs2019上测试 大小是8啊

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 5月26日
  • 已采纳回答 5月18日
  • 创建了问题 5月16日