NO.254 指针赋值
本帖最后由 我爱橙 于 2022-3-10 16:57 编辑已知p,p1为指针变量,a为数组名,j为整型变量,
下列赋值语句中不正确的是
A.p=&j,p=p1;
B.p=a;
C.p=&a;
D.p=10; //p是指针变量存放地址,不能赋值整形常量10
A.a=d
#include <stdio.h>
#include <math.h>
int main()
{
int a,*p,*p1,j;
p=&j,p=p1;
printf("a=d\n",a);
printf("*p=%d\n",*p);
printf("p=%d\n",p);
printf("a=%d\n",a);
return 0;
}
B.
#include <stdio.h>
#include <math.h>
int main()
{
int a,*p,*p1,j;
p=a;
printf("a=d\n",a);//a=d
printf("*p=%d\n",*p);//*p=0
printf("p=%d\n",p);//p=6487552
printf("a=%d\n",a);//a=0
return 0;
}
C.
#include <stdio.h>
#include <math.h>
int main()
{
int a,*p,*p1,j;
p=a;
printf("a=d\n",a);//a=d
printf("*p=%d\n",*p);//*p=1
printf("p=%d\n",p);//p=6487536
printf("a=%d\n",a);//a=1
return 0;
}
页:
[1]