鱼C论坛

 找回密码
 立即注册
查看: 3307|回复: 0

[学习笔记] NO.254 指针赋值

[复制链接]
发表于 2022-3-10 16:57:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 我爱橙 于 2022-3-10 16:57 编辑

已知p,p1为指针变量,a为数组名,j为整型变量,
下列赋值语句中不正确的是
A.p=&j,p=p1;
B.p=a;
C.p=&a[j];
D.p=10;         //p是指针变量存放地址,不能赋值整形常量10

A.a[5]=d
  1. #include <stdio.h>
  2. #include <math.h>

  3. int main()
  4. {
  5.       int a[5],*p,*p1,j;
  6.       p=&j,p=p1;
  7.           printf("a[5]=d\n",a[5]);
  8.           printf("*p=%d\n",*p);
  9.           printf("p=%d\n",p);
  10.           printf("a[0]=%d\n",a[0]);
  11.        
  12.          
  13.      

  14.         return 0;
  15.         
  16. }
复制代码







B.
  1. #include <stdio.h>
  2. #include <math.h>

  3. int main()
  4. {
  5.       int a[5],*p,*p1,j;
  6.       p=a;
  7.           printf("a[5]=d\n",a[5]);//a[5]=d
  8.           printf("*p=%d\n",*p);//*p=0
  9.           printf("p=%d\n",p);//p=6487552
  10.           printf("a[0]=%d\n",a[0]);//a[0]=0
  11.        
  12.          
  13.      

  14.         return 0;
  15.         
  16. }
复制代码


C.
  1. #include <stdio.h>
  2. #include <math.h>

  3. int main()
  4. {
  5.       int a[5],*p,*p1,j;
  6.       p=a;
  7.           printf("a[5]=d\n",a[5]);//a[5]=d
  8.           printf("*p=%d\n",*p);//*p=1
  9.           printf("p=%d\n",p);//p=6487536
  10.           printf("a[0]=%d\n",a[0]);//a[0]=1
  11.        
  12.          
  13.      

  14.         return 0;
  15.         
  16. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-17 18:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表