无聊的测试-union

来源:互联网 发布:linux与ubuntu的区别 编辑:程序博客网 时间:2024/05/17 07:05

// t.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

union
{
 int i;
 char x[2];
}a;

 


int _tmain(int argc, _TCHAR* argv[])
{
 a.x[0]=10;
 a.x[1]=1;//   0x01  0x0A==266

 cout<<a.i<<endl;
 
 while(1);
 return 0;
}

 

 

 

// t.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

union
{
 char ch;
 int i;
 char x[2];
 long double k;
 double j;
 long int a;
}a;

 


int _tmain(int argc, _TCHAR* argv[])
{
 

 cout<<sizeof(a)<<endl;
 
 while(1);
 return 0;
}

 

原创粉丝点击