1.函数指针
这个指针返回一个函数
int (*f) (int x); /* 声明一个函数指针 */
f=func; /* 将func函数的首地址赋给指针f */
2.函数指针数组
这个指针返回一组函数
#include "stdio.h"
void function0(void);
void function1(void);
void function2(void);
void (*f[3])(void) = {function0,function1,function2};
void main()
{
(*f[0])();
}
void function0(void)
{
printf( "You entered 1 so function was called\n\n");
}
void function1(void)
{
printf( "You entered 2 so function was called\n\n");
}
void function2(void)
{
printf( "You entered 3 so function was called\n\n");
}
3.指针函数
这个函数返回一个指针
int * GetDate(int wk,int dy);
main()
{
int wk,dy;
do
{
printf(Enter week(1-5)day(1-7)\n);
scanf(%d%d,&wk,&dy);
}
while(wk<1||wk>5||dy<1||dy>7);
printf(%d\n,*GetDate(wk,dy));
}
int * GetDate(int wk,int dy)
{
static int calendar[5][7]=
{
{1,2,3,4,5,6,7},
{8,9,10,11,12,13,14},
{15,16,17,18,19,20,21},
{22,23,24,25,26,27,28},
{29,30,31,-1}
};
return &calendar[wk-1][dy-1];
}