猿问

返回指针值的函数

程序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是正确的;

原因找不出呢;

求解;



繁星coding
浏览 845回答 1
1回答

呼唤远方

程序1#include<stdio.h>int main(){&nbsp;float * search (float (* pointer)[4] , int n);&nbsp;float score[][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}};&nbsp;float *p;&nbsp;int i, m;&nbsp;printf("输入学生学号\n");&nbsp;scanf("%d",&m);&nbsp;printf("The scoer of No.%d are:\n",m);&nbsp;p=search(score,m);&nbsp;for(i=0; i<4; i++);&nbsp;printf("%5.2f\n",*(p+i));&nbsp;printf("\n");&nbsp;return 0;}float * search (float (* pointer)[4] , int n){float * pt;pt=* (pointer+n);return (pt);}把for后面的;去掉
随时随地看视频慕课网APP
我要回答