/*返回指针的函数 */
#include <stdio.h>
/*1.float(*pointer)[n]会把从参数中传递进来的数据进行分行,n个数为一行
* 2.原数组score为4行3列(score标识)
* 3.执行float(*pointer)[4]后数组score被重新划分为3行4列(用pointer标识)*/
#include <stdlib.h>
int main(void){
float score[][3]={60,70,80,90,56,89,67,88,34,78,90,66};
float *search();
float *p;
int i,k;
printf("enter the number of student:");
fflush(stdout);
scanf("%d",&k);
printf("the score of No.%d are:\n",k);
p=search(score,k);//通过二维数组入口地址传递到*search()中去,数组进行分组,4个为一组,并用p标记pointer
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;
}
调试结果
enter the number of student:2
the score of No.2 are:
34.00 78.00 90.00 66.00