#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;
}

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

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

posted on 2025-02-28 12:20  轩~邈  阅读(12)  评论(0)    收藏  举报