标签:style blog color io os ar sp div c
方法一:
#include<stdio.h> #include<stdlib.h> int main(int argc ,char *argv[]) { union name{ int i; char a; }c; c.i=0x04030201; printf("%d\n",c.a);//输出4为大端存储,输出1为小端存储 return 0; }
方法二:
#include <stdio.h> typedef union{ unsigned int a; unsigned char b[4]; }Endian; int main() { Endian test; test.a=0x12345678; printf("%s\n",(0x12 == test.b[0])?"Big Endian":"Small Endian"); return 0; }
方法三:
#include<stdio.h> #include<iostream.h> void main() { union w { int m ; char n ; }; w ww ; ww.m=1 ; if(ww.n==1) printf("it is little-endian "); else printf("it is libig-endian "); }
标签:style blog color io os ar sp div c
原文地址:http://www.cnblogs.com/gjianw217/p/4002353.html