#include <stdio.h>
int Endianness(void)//1 if the machine is little-endian, 0 if the is big-endian
{
union
{
int theInteger;
char singleByte;
}endianTest;
endianTest.theInteger=1;
return endianTest.singleByte;
}
int Endianness2(void)//1 if the machine is little-endian, 0 if the is big-endian
{
int testNum=1;
char*ptr=(char*)&testNum;
return (*ptr);
}
int main()
{
int x=1;
// if (*(char*)&x==1)
if (*(char*)&x)
{
printf("小端系统/n");
}
if (Endianness())
{
printf("小端系统/n");
}
if (Endianness2())
{
printf("小端系统/n");
}
else
printf("大端系统/n");
return 0;
}