标签:结构体 空间 type void def struct 大小 main int
typedef struct
{
int num:16; //指定num所占空间为16位,即2字节
}A1;
typedef struct
{
int num:16; //3个16位,本来为6字节,补齐为8字节
int num1:16;
int num2:16;
}A2;
typedef struct
{
int num:8; //1个8位,本来为1字节,补齐为4字节
}A3;
typedef struct
{
int num:8; //3个8位,本来为3字节,补齐为4字节
int num1:8;
int num2:8;
}A4;
int main(void)
{
A1 a1;
A2 a2;
A3 a3;
A4 a4;
cout << sizeof(a1)<<endl; //4
cout << sizeof(a2)<<endl; //8
cout << sizeof(a3)<<endl; //4
cout << sizeof(a4)<<endl; //4
}
标签:结构体 空间 type void def struct 大小 main int
原文地址:http://www.cnblogs.com/linuxAndMcu/p/7560191.html