参考链接;https://www.cnblogs.com/dylancao/p/8472879.html
代码:
1 #include <stdio.h> 2 3 int checkCPU() 4 { 5 union w 6 { 7 int a; 8 char b; 9 }c; 10 c.a = 1; 11 return (c.b == 1); // 小端返回TRUE,大端返回FALSE 12 } 13 14 int main() 15 { 16 int ret = 0; 17 18 ret = checkCPU(); 19 if (ret == 1) 20 printf("litttle endian "); 21 else 22 printf("big endian "); 23 24 return 0; 25 }