/***********************************************************************
功能:使用指针函数求学生成绩
日期:2014年12月7日10:21:11
***********************************************************************/
#include<stdio.h>
float *search(float (*p)[4], int n)//形参是指向数组长度为4的指针变量p,和整型变量n
{ //
float *pt;
pt =*(p + n);//把第n个元素的地址赋给pt,这里的元素指的是二维数组的第n列,我是这么理解的,不知道对不对
return (pt);
}
void main()
{
float score[][4] = {{60,75,82,91}, {75,81,91,90}, {51,65,78,84}, {65,51,78,72}};
float *p;
int i, j;
printf("Enter the student's number you want to search:");
scanf("%d", &j);
printf("The student's scores are:\n");
p = search(score, j);
for(i = 0; i < 4; i++)
printf("%5.1f\t", *(p + i));
}
/***********************************************************************
Enter the student's number you want to search:2
The student's scores are:
51.0 65.0 78.0 84.0 Press any key to continue
***********************************************************************/
使用指针函数求学生成绩
最新推荐文章于 2022-05-15 14:57:01 发布