判断PC机大小端
1 #include2 #include 3 4 int main() 5 { 6 short a = 0x0102; 7 char *p = (char*)(&a); 8 9 //低字节存储在低地址10 if(*p == 2 && *(p + 1) == 1)11 printf("小端\n");12 13 //高字节存储在低地址14 else if(*p == 1 && *(p + 1) == 2)15 printf("大端\n");16 17 return 0;18 }