#include <stdio.h>
#include <stdlib.h>
void function1(int);
void function2(int);
void function3(int);
int main(int argc, char *argv[])
{
void (*f[3])(int) ={function1,function2,function3};//???
int choice;
printf("enter a number between 0,23 to end\n");
scanf("%d",&choice);
while(choice>=0&&choice<3){
(*f[choice])(choice); //为什么这样调用?
printf("enter a number between 0 and 2,3 to end");
scanf("%d",&choice);
}
printf("you entered 3 to end");
system("PAUSE");
return 0;
}
void function1(int a){
printf("you entered %d so function1 is called\n\n",a);
}
void function2(int b){
printf("you entered %d so function2 is called\n\n",b);
}
void function3(int c){
printf("you entered %d so function3 is called\n\n",c);
}
c语言函数指针使用范例
最新推荐文章于 2023-06-20 19:25:57 发布