指针与函数_函数指针数组

来源:互联网 发布:matlab软件官网 编辑:程序博客网 时间:2024/06/07 10:39

声明一个函数指针数组

typedef int (*operation)(int,int);

operation operations[128]={NULL};

或者

int (*operations[128])(int)={NULL};

#include<stdio.h>int add(int num1, int num2){    return num1 + num2;}int subtract(int num1, int num2){    return num1 - num2;}typedef int(*fptrOperation)(int, int);int main(void){    fptrOperation operations[10] = {NULL};    operations[0] = add;    operations[1] = subtract;    printf("%d\n", (operations[0])(5,6));    printf("%d\n", (operations[1])(5,6));    return 0;}