大小端; union

                                               

#include<stdio.h>
#include <stdlib.h>

typedef union {
   int m;
   char a[4];
}Node;



int main (){
    Node node;//

       node.m = 0x01020304;  // 16进制 转化为10 进制;


       printf("sizeof(int) = %d 
" ,sizeof( int) );
       printf("sizeof(char) = %d
" ,sizeof( char));

       printf("%d
" , node. m);

       printf("char[0] = %x
" ,node. a[0]);
       printf("char[1] = %x
" ,node. a[1]);
       printf("char[2] = %x
" ,node. a[2]);
       printf("char[3] = %x
" ,node. a[3]);



       if(node .a[0] == 0x4){
         printf(" 小端"); // 大小 与顺序相反是小端 ;
      }
       if(node .a[0] == 0x1){
         printf(" 大端");
      }

   return 0; //
}

  

原文地址:https://www.cnblogs.com/vagabond/p/4996329.html