所以我正在浏览我的 C 编程教科书,我看到了这段代码。
#include <stdio.h>
int j, k;
int *ptr;
int main(void)
{
j = 1;
k = 2;
ptr = &k;
printf("\n");
printf("j has the value %d and is stored at %p\n", j, (void *)&j);
printf("k has the value %d and is stored at %p\n", k, (void *)&k);
printf("ptr has the value %p and is stored at %p\n", (void *)ptr, (void *)&ptr);
printf("The value of the integer pointed to by ptr is %d\n", *ptr);
return 0;
}
我运行它,输出是:
j 的值为 1 并存储在 0x4030e0
k 的值为 2 并存储在 0x403100ptr 的值为 0x403100 并存储在 0x4030f0
ptr指向的整数的值为2
我的问题是,如果我没有通过编译器运行它,你怎么能通过查看这段代码来知道这些变量的地址?我只是不确定如何获取变量的实际地址。谢谢!