鱼C论坛

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

NO.194 指针指向

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

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

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

x
Q:若有double *p,x[10];int i=5;
使指针变量p指向元素x[5]的语句是
A.p=&x[i];
B.p=x;
C.p=x[i];
D.p=&(x+i);


B×  p=x是指向数组首元素地址




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

  3. int main()
  4. {
  5.       double *p,x[10];int i=5;
  6.       p=&x[i];
  7.           printf("p=%lf\n",p);//p=0.000000
  8.           printf("*p=%lf\n",*p);//*p=0.000000
  9.           printf("x[0]=%lf\n",x[0]);//x[0]=0.000000
  10.        
  11.          
  12.      

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


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

  3. int main()
  4. {
  5.       double *p,x[10];int i=5;
  6.       p=x;
  7.           printf("p=%lf\n",p);//p=0.000000
  8.           printf("*p=%lf\n",*p);//*p=0.000000
  9.           printf("x[0]=%lf\n",x[0]);//x[0]=0.000000
  10.        
  11.          
  12.      

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



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

  3. int main()
  4. {
  5.       double *p,x[10];int i=5;
  6.          p=x[i];
  7.           printf("p=%lf\n",p);
  8.           printf("*p=%lf\n",*p);
  9.           printf("x[0]=%lf\n",x[0]);
  10.        
  11.          
  12.      

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


7        11
[Error] cannot convert 'double' to 'double*' in assignment


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

  3. int main()
  4. {
  5.       double *p,x[10];int i=5;
  6.       p=&(x+i);
  7.           printf("p=%lf\n",p);
  8.           printf("*p=%lf\n",*p);
  9.           printf("x[0]=%lf\n",x[0]);
  10.        
  11.          
  12.      

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


7        14       
[Error] lvalue required as unary '&' operand
[错误]左值需要作为一元'&'操作数
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-17 17:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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