为了账号安全,请及时绑定邮箱和手机立即绑定

返回指针值的函数

返回指针值的函数

繁星coding 2018-08-13 15:14:56
程序1#include<stdio.h>int main(){ float * search (float (* pointer)[4] , int n); float score[][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}}; float *p; int i, m; printf("输入学生学号\n"); scanf("%d",&m); printf("The scoer of No.%d are:\n",m); p=search(score,m); for(i=0; i<4; i++); printf("%5.2f\n",*(p+i)); printf("\n"); return 0;}float * search (float (* pointer)[4] , int n){float * pt;pt=* (pointer+n);return (pt);}  程序2 #include <stdlib.h> int main(){    float score[][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}};    float *search(float (*pointer)[4],int n);       //函数声明    float *p;    int i,m;    printf("enter the number of student:");    scanf("%d",&m);    printf("The score of No.%d are:\n",m);    p = search(score,m);                            //函数调用    for(i=0;i<4;i++)        printf("%5.2f\t",*(p+i));    printf("\n");    return 0;}float *search(float (*pointer)[4],int n){    float *pt;    pt = *(pointer+n);    return(pt);}   程序1运行结果不对;程序2是正确的;原因找不出呢;求解;
查看完整描述

1 回答

?
呼唤远方

TA贡献1856条经验 获得超11个赞

程序1

#include<stdio.h>
int main()

{
 float * search (float (* pointer)[4] , int n);

 float score[][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}};

 float *p;

 int i, m;

 printf("输入学生学号\n");

 scanf("%d",&m);

 printf("The scoer of No.%d are:\n",m);

 p=search(score,m);

 for(i=0; i<4; i++);

 printf("%5.2f\n",*(p+i));

 printf("\n");
 return 0;
}
float * search (float (* pointer)[4] , int n)
{
float * pt;
pt=* (pointer+n);
return (pt);
}

把for后面的;去掉

查看完整回答
反对 回复 2018-09-11
  • 1 回答
  • 0 关注
  • 844 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信