qfedu-c-level/day8/d4.c

13 lines
487 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
int main()
{
int m = 0x1020;
int *p = &m;
printf("%p, %#x\n", p, *p);
char *q = (char *)&m; // 原理强制类型转换将int类型的地址强制转换为char类型的地址这样就可以一个字节一个字节的读取了
printf("%p, 低位: %#x\n", q, *q); // 0x20 因为是小端模式,原理同上
printf("%p, 高位: %#x\n", q, *(q + 1)); // 0x20 因为是小端模式,原理同上
return 0;
}