码迷,mamicode.com
首页 > 编程语言 > 详细

union、enum、struct 内存分配问题

时间:2017-04-20 16:06:19      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:pac   logs   blog   char   ima   out   pack   img   oat   

代码和运行结果一看就懂了。

union un
{
int m;
float c;
double p;
long k;
unsigned int q;
long long g;
__int64 o;
};
enum em
{
a,b,c,d
};
struct MyStruct
{
char a;//4
float c;//4
char b;//4
double p;//8
char m1;
int k;//8
char kk;
};
struct MyStruct1
{
char a;//4
};
struct MyStruct2
{
char a;//4
float c;//4
};
#pragma pack(16)
struct MyStruct3
{
char a;//4
double c;//4
};
#pragma pack()
struct MyStruct4
{
char m;
float a;
int a1;
double c;//4
float b;
};
cout << "int=" << sizeof(int) << endl;
cout << "float=" << sizeof(float) << endl;
cout << "double=" << sizeof(double) << endl;
cout << "long=" << sizeof(long) << endl;
cout << "char=" << sizeof(char) << endl;
cout << "unsigned int=" << sizeof(unsigned int) << endl;
cout << "long long=" << sizeof(long long) << endl;
cout << "__int64=" << sizeof(long double ) << endl;
cout << "MyStruct1=" << sizeof(MyStruct1) << endl;
cout << "MyStruct2=" << sizeof(MyStruct2) << endl;
cout << "MyStruct3=" << sizeof(MyStruct3) << endl;
cout << "MyStruct4=" << sizeof(MyStruct4) << endl;
cout << sizeof(un) << endl << sizeof(em)<<endl << sizeof(MyStruct)<<endl;

技术分享

union、enum、struct 内存分配问题

标签:pac   logs   blog   char   ima   out   pack   img   oat   

原文地址:http://www.cnblogs.com/ghl0109/p/6739245.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!