标签:字节对齐 sizeof 空结构体长度 struct结构体长
请仔细查看和对比,尤其是注释掉的结果。
/* 编辑编译环境:Dev-C++ 4.9.9.2 */
/* source: */
#include "stdio.h"
struct S{ };
struct S1{
char a;
long b;
};
struct S2 {
char c;
struct S1 d;
long long e;
};
struct S3{
long b;
char a;
};
int main(void)
{
// result:
printf("sizeof(char) = %d /n",sizeof(char)); // 1
printf("sizeof(long) = %d /n",sizeof(long)); // 4
printf("sizeof(long long) = %d /n",sizeof(long long)); // 8
printf("struct S = %d /n",sizeof(struct S)); // 1
printf("struct S1 = %d /n",sizeof(struct S1)); // 8
printf("struct S2 = %d /n",sizeof(struct S2)); // 24
printf("struct S3 = %d /n",sizeof(struct S3)); // 8
while(1);
}
标签:字节对齐 sizeof 空结构体长度 struct结构体长
原文地址:http://blog.csdn.net/liranke/article/details/46333271