1.使用共用体判断大端存储和小端存储
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
union judge{
int a;
char b;
};
int main(int argc,const char *argv[])
{
union judge s;
s.a=0x12345678;
if(s.b==0x12)
{
printf("大端存储\n");
}
else if(s.b==0x78)
{
printf("小端存储\n");
}
return 0;
}