`

C中联合体的简单示例

阅读更多

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

union Un
{
	int		a;
	char	ch;
	float	f;
	double	du;
};

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

	u.a = 97;

	cout << "sizeof(u) = " << sizeof(u) << endl;
	cout << "a = " << u.a << endl;
	cout << "ch = " << u.ch << endl;
	cout << "f = " << u.f << endl;
	cout << "du = " << u.du << endl;
	
	return 0;
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics