//写一个程序判断编译器是大端还是小端
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int a = 0x11223344;
	char *p = (char*)&a;
	if (*p == 0x11)
	{
		printf("大端");
	}
	else
	{
		printf("小端");
	}
	system("pause");
	return 0;
}

大于一个字节的程序都存在大端小端存储,大端即高位放在地位存储,低位放在高位存储,而小端相反


int a=1;//0x00000001

如果是小端存储则输出01,若是大端则输出0x


方法二:

union关键字

union中所有成员共用一个空间,同一时间只存储一个数据成员,所有数据成员具有相同的起始地址

#include<stdio.h>
#include<stdlib.h>

int main()
{
	union check
	{
		int a;
		char b;
	}c;
	c.a = 1;
	if (c.b == 1)
		printf("small");
	else
		printf("big");
	
	system("pause");
	return 0;
}