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

admin2013-06-11  25

问题 有以下程序    #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

解析 指针变量在定义时需要加星号,而在赋值时则不用,故选项B)错误。本题中,scanf()函数和printf()函数都是要对指针变量p指向的地址处的数据进行访问,不是变量本身。选项C)中多了取地址运算符,选项D)中少了指针运算符。
转载请注明原文地址:https://kaotiyun.com/show/5wJp777K
0

最新回复(0)