#include <stdio.h>
#include <malloc.h>
union myunion
{
int a;
char b; // 成员b占低地址的1个字节
};
int main(void)
{
union myunion test;
test.a = 0x87654321;
if (test.b == 0x87)
printf("大端模式"); //低地址存高字节
else if (test.b == 0x21)
printf("小端模式"); //低地址存低字节
return 0;
}
小端:低地址放低字节,高地址放高字节

大端:低地址放高字节,高地址放低字节

联合体成员低地址对齐
浙公网安备 33010602011771号