#include "stdio.h"
void func1(int);
void func2(int);
void func3(int);
int main()
{
void (*f_ptr[3])(int) = {func1,func2,func3}; //f_ptr是存放三個function pointer的陣列,每個function都有一個int的引數
int choice;
while(1)
{
printf("Enter your num to choice function(0~2): \n ");
scanf("%d",&choice);
if(choice >= 0 || choice <=3)
{
(*f_ptr[choice])(choice);
}
}
return 0;
}
void func1(int input)
{
printf("You choice func %d.\n",input);
}
void func2(int input)
{
printf("You choice func %d.\n",input);
}
void func3(int input)
{
printf("You choice func %d.\n",input);
}
沒有留言:
張貼留言