c++ - : operator in c/c++

标签 c++ c

谁能告诉我,这段代码发生了什么?我尝试搜索很多地方,但无法理解代码的注释部分到底在做什么。

#include<stdio.h>

struct XYZ {
    //int a:6; this one.
    char s; 
}structure;

int main() {
     printf("%lu",sizeof(structure)); 
     return 0;
}

我得到的输出为 4。

最佳答案

该行已被注释掉。它没有做任何事情。

如果没有注释掉,则意味着int a的大小仅限于6位。它对于结构内部的位字段很有用。

关于c++ - : operator in c/c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17617724/

相关文章:

c++ - 终端错误 MacOS :/Applications/Xcode. app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1634:1: 注意:

c++ - 在 Windows 7 中安装 Subversion(以及一般的 C 库)

c++ - 在 8 字节边界上对齐 double ?

c - "One or more output arguments not assigned during call to "input_4”是什么意思?

c - 如何在C中将RGB转换为HSL?

c++ try catch 实践

c++ - 使用升压锁进行 RAII 对信号量的访问

c++ - 我需要在重新分配指针之前调用 delete 吗?

使用集合列表创建数组

c++ - 字符串 "sizeof"的意外结果