C语言 struct结构体的变量声明加冒号
struct mybitfields
{
unsigned short a : 4;
unsigned short b : 5;
unsigned short c : 7;
} test;
=> sizeof(test) ==2;
struct mybitfields
{
unsigned char a : 4;
unsigned char b : 5;
unsigned char c : 7;
} test;
=> sizeof(test) ==3;
struct mybitfields
{
unsigned char a : 4;
unsigned short b : 5;
unsigned char c : 7;
} test;
=> sizeof(test) ==6;
struct mybitfields
{
unsigned short a : 4;
unsigned char b : 5;
unsigned char c : 7;
} test;
=> sizeof(test) ==4;
struct mybitfields
{
unsigned char a : 4;
unsigned char b : 5;
unsigned short c : 7;
} test;
=> sizeof(test) ==4;
struct mybitfields
{
unsigned char a : 4;
unsigned int b : 5;
unsigned short c : 7;
} test;
=> sizeof(test) ==12;
5、常用内置类型的字节数
对于32位编译器来说:
char: 1个字节
指针变量: 4个字节(32位的寻址空间是2^32,即32个bit,也就是4个字节。同理64位编译器)
short int : 2个字节
int: 4个字节
unsigned int :4个字节
float: 4个字节
double: 8个字节
long: 4个字节
long long: 8个字节
unsigned long:4个字节
转载自:https://blog.51cto.com/u_13675550/6077388
c++中冒号(:)和双冒号(::)的用法 https://blog.csdn.net/qq_33375598/article/details/89148805
https://www.cnblogs.com/paul-617/p/15690849.html