谁能告诉我,这段代码发生了什么?我尝试搜索很多地方,但无法理解代码的注释部分到底在做什么。
#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/