- #include<stdio.h>
- int test_endian(void)
- {
- int a=0x12345678; /*测试用的数据*/
- char *p;
- p=(char *)(&a); /*将其地址转换为一个字符型数据的指针*/
- if(*p==0x78) /*判断最低一个字节的数据*/
- return 1;
- return 0;
- }
- int main()
- {
- if(test_endian()==1)
- printf("The little endian/n"); /*小端法存储*/
- else
- printf("The big endian/n"); /*大端法存储*/
- return 0;
- }
可做成库以便测试本机数据存储形式时使用。