标签:sizeof 语言 include summer har color stdio.h int 针对
由下面的测试代码可以总结出两点:(1)内存对齐是针对结构体而言的 (2)编译时char类型的申请的空间由其后面的数据类型决定。
#include<stdio.h> enum Season { Spring,Summer,Autumn }; enum ENUM Enum = Autumn; union UNION { int a; char b; double c; }; union UNION Union; struct STRUCT { char b; //4字节 int a; //4字节 char d; //4字节 int c; //4字节 }; struct STRUCT Struct; struct STRUCT2 { char b; //4字节 int a; //4字节 char d; //8字节 double c; //8字节 }; struct STRUCT2 Struct2; int main() { printf("%d\n",sizeof(Enum)); //4 枚举变量占4个字节 printf("%d\n",sizeof(Union)); //8 printf("%d\n",sizeof(Struct)); //16 内存对齐 printf("%d\n",sizeof(Struct2)); //24 内存对齐 return 0; }
标签:sizeof 语言 include summer har color stdio.h int 针对
原文地址:http://www.cnblogs.com/Pual623548198/p/6685567.html