1:思维导图
2:计算结构体大小
3:大小端存储
(1):数据溢出
1 #include <stdio.h>2 #include <string.h>3 #include <stdlib.h>4 int main(int argc, const char *argv[])5 {6 short a = 0x1234;7 char c = (char)a;8 9 if(c==0x12) 10 {11 printf("大端存储\n");12 }13 else14 {15 printf("小端存储\n");16 }17 return 0;18 }
(2):指针
1 #include <stdio.h>2 #include <string.h>3 #include <stdlib.h>4 int main(int argc, const char *argv[])5 {6 short a = 0x1234;7 char *p =&a;8 9 if(*p==0x12)10 {11 printf("大端存储\n");12 }13 else14 {15 printf("小端存储\n");16 }17 return 0;18 }
(3):共用体
1 #include <stdio.h>2 #include <string.h>3 #include <stdlib.h>4 union A5 {6 int a1;7 char a2;8 };9 int main(int argc, const char *argv[])10 {11 union A num;12 num.a1 = 0x12345678;13 14 if(num.a2==0x12)15 {16 printf("大端存储\n");17 } 18 else if(num.a2=0x78)19 {20 printf("小端存储\n"); 21 }