返回指针值的函数
int *a ( int x, int y );
a是函数名,调用它以后能得到一个指向整型数据的指针.*a两侧没有括号,在a的两侧分别为*运算符和()运算符
而()的优先级高于*.因此a先与()先结合,这个函数前面有*,表示此函数是指针型函数,最前面的int表示返回的
指针指向整型变量.
eg:有三个学生,每个学生有4门课,功能:用户输入学生序号,就能输出该学生的成绩
# include <stdio.h> int main ( void ) { 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 ); //score的首地址给pointer; for ( i = 0; i < 4; i ++ ) { printf ( "%5.2f/t", *( p + i ) ); printf ( "\n" ); } } float *search ( float ( *pointer )[ 4 ], int n ) { float *pt; pt = *( pointer + n ); return ( pt ); }
结果:

浙公网安备 33010602011771号