要输入内存地址,请使用%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;
}
要输入内存地址,请使用%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;
}