为什么输入0或2位数时p值会有所不同 [英] why p value comes different on entering 0 or 2 digit number
本文介绍了为什么输入0或2位数时p值会有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
int main()
{
int a=10,*p=&a;
printf("%u\n%u\n%u\n%u\n",&p,&a,p,*p);
scanf("%d",p);
//scanf("%p",p);
printf("%d..%d\n%d\n%u\n",*p,p,a,&p);
}
~
~
推荐答案
您正在打印不同的东西在两个不同的printf
语句中,您是错误的格式说明符。它应该是:
You are printing different things in the two differentprintf
statements and you are the wrong format specifiers. It should be:
#include<stdio.h>
int main()
{
int a=10,*p=&a;
printf("%p\n%p\n%p\n%d\n",&p,&a,p,*p);
if ( scanf("%d",p) != 1 ) return -1;
//scanf("%p",p);
printf("%d..%p\n%d\n%p\n",*p,p,a,&p);
return 0;
}
这篇关于为什么输入0或2位数时p值会有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文