小编ste*_*eve的帖子

为什么以下程序中的输出为12个字节,而总大小仅为6位?

变量v的大小为12个字节,但由于它的大小为6位,为什么它不是4个字节?

#include <iostream>
using namespace std;

struct abc {
    int c : 4;
    char x : 1;
    int y : 1;
} v;

int main()
{
    cout << sizeof v; // it prints 12 . why?
}
Run Code Online (Sandbox Code Playgroud)

c++ structure sizeof

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

标签 统计

c++ ×1

sizeof ×1

structure ×1