scanf与printf语句

来源:百度知道 编辑:UC知道 时间:2024/05/27 12:01:52
#include<stdio.h>
void main()
{
int n,*p=NULL;
p=&n;
printf("Input n:");
scanf("%d",p);
printf("output n:");
printf("%d\n",*p);
}
程序通过指针p为变量n读入数据并输出,程序中中的printf和scanf语句是否有错误?

没错
printf函数是输出变量的值
scanf函数是向变量地址中写入值

printf("output n:"); 这一句好像不是输出n的值吧,

应改成这样:

printf("output n:",n);

才是你想要的结果吧

正确,scanf用指针,printf用变量本身

对呀!没有错误!