#include<stdio.h>
union{
int i;
unsigned char ch[2];
}student;
int main()
{
student.i=0x1420;
printf("%d %d",student.ch[0],student.ch[1]); return 0;
}
小段模式
地址A
----------------------------------
|A |A+1 |A+2 |A+3 | int a;对应右边:(A)20 (A+1)14 (A+2)00 (A+3)00
|0x01 |0x00 |0x00 |0x00 |
-----------------------------------
|A |A+1 char b;
| ch[0] |ch[1] |
int student.i=0x1420; 又是小端模式,所以存储顺序: 0x20 0x14
然后student.ch[]是char型的 占一个字节 先后对应 0x20 0x14 十进制即; 32 20