判断计算机的字节序(大端或小端)的程序如下:
#include <stdio.h>
int main() {
unsigned int num = 0x12345678;
unsigned char *p = (unsigned char *)&num;
if (*p == 0x78) {
printf("Little Endian\n");
} else {
printf("Big Endian\n");
}
return 0;
}
这段程序通过将一个整数(0x12345678)存储到内存中