要输入内存地址,请使用%p格式说明符。带有%p的scanf()可以读取CPU定义的格式的地址。
例如,该程序输入一个地址,然后显示该内存地址的内容:
#include <stdio.h>
int main(void)
{
char *p;
printf("Enter an address: ");
scanf("%p", &p);
printf("Value at location %p is %c/n", p, *p);
return 0;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/266509.html