您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页返回指针值的 函数

返回指针值的 函数

来源:化拓教育网

  这种返回指针值的函数,一般定义形式为

  类型名 * 函数名 ( 参数列表 )     例如 int *a( int x,int y);

  例:有若干学生的成绩(每个学生有4门成绩),要求在用户在输入学生序号以后,能输出该学生的全部成绩。用指针函数来实现。


1 #include < stdio.h >
2 #include < stdlib.h >
3
4   int main()
5 {
6 float score[][ 4 ] = {{ 60 , 70 , 80 , 90 },{ 56 , , 67 , 88 },{ 34 , 78 , 90 , 66 }};
7 float * search( float ( * pointer)[ 4 ], int n); // 函数声明
8 float * p;
9 int i,m;
10 printf( " enter the number of student: " );
11 scanf( " %d " , & m);
12 printf( " The score of No.%d are:\n " ,m);
13 p = search(score,m); // 函数调用
14 for (i = 0 ;i < 4 ;i ++ )
15 printf( " %5.2f\t " , * (p + i));
16 printf( " \n " );
17
18 return 0 ;
19 }
20
21 float * search( float ( * pointer)[ 4 ], int n)
22 {
23 float * pt;
24 pt = * (pointer + n);
25 return (pt);
26 }

  

转载于:https://www.cnblogs.com/zxl2431/archive/2011/03/25/1995658.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务