字节对齐

#include <stdio.h>

struct Example {
    int a;          // 4 bytes
    char b[32];     // 32 bytes
    double c;       // 8 bytes
};

int main() {
    struct Example ex;
    printf("Size of struct Example: %lu bytes\n", sizeof(ex));
    return 0;
}

运行结果为:Size of struct Example: 48 bytes

所以,正确答案是结构体Example的大小为48字节。非常抱歉之前给您带来的困惑。

posted on 2023-09-26 14:50  开源侠  阅读(17)  评论(0)    收藏  举报