From 9bf32f9692e7977dfc5306b46ca1745d39f57933 Mon Sep 17 00:00:00 2001 From: flykhan Date: Thu, 13 Jul 2023 09:30:11 +0800 Subject: [PATCH] =?UTF-8?q?day8=20coding:=20=E6=8C=87=E9=92=88=E7=9A=84?= =?UTF-8?q?=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day8/d4.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 day8/d4.c diff --git a/day8/d4.c b/day8/d4.c new file mode 100644 index 0000000..0aa992d --- /dev/null +++ b/day8/d4.c @@ -0,0 +1,13 @@ +#include + +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; +} \ No newline at end of file