标签:
#include <stdio.h> union{ int i; char x[2]; }a; int main(){ a.x[0] = 10; a.x[1] = 1; printf("%d", a.i); }
结果是266(低位低地址,高位高地址,内存占用情况0x010A)
int main(){ union{ int i; struct{ char first; char second; }half; }number; number.i = 0x4241; printf("%c%c\n", number.half.first, number.half.second); number.half.first = ‘a‘; number.half.second = ‘b‘; printf("%x\n", number.i); return 0; }
AB(0x41,对应‘A’,是低位;0x42,对应‘B’,是高位)
6261(number.i和number.half共用一块地址空间)
标签:
原文地址:http://www.cnblogs.com/yingl/p/5816249.html