有以下程序 #include<stdio.h> main() {int n,*p=NULL; *p=&n; printf("Input n:");scanf("%d",&p);printf("output n:"); printf("%d\n",p);}

admin2016-12-18  22

问题 有以下程序
#include<stdio.h>
main()
{int n,*p=NULL;
*p=&n;
printf("Input n:");scanf("%d",&p);printf("output n:");
printf("%d\n",p);}
该程序试图通过指针p为变量n读入数据并输出,但程序有多处错误,以下语句正确的是

选项 A、int n,*p=NULL;
B、*p=&n;
C、scanf("%d",&p)
D、printf("%d\n",p);

答案A

解析 选项A)表示在程序中,声明定义变量语句“int n,*p=NULL;”定义了整型变量n和指针变量p,并且指针变量p初始化为空。其他的语句都是错误的。其中选项B),&n的地址应存放到指针变量p中,而选项C)中数据输入项错误,选项D)输出地址信息。
转载请注明原文地址:https://kaotiyun.com/show/G8Dp777K
0

最新回复(0)