回调函数的使用2

来源:互联网 发布:跳蚤街 淘宝二手市场 编辑:程序博客网 时间:2024/06/07 21:31
为了降低函数的圈复杂度,可以通过查表来调用函数:
#include <stdio.h>
#if 1
typedef int (*pfCallBack)();

int test1()
{
    int i = 0;
    i++;
    printf("%d",i);
    return 1;
}
int test2()
{
    int i = 1;
    i++;
    printf("%d",i);
    return 1;
}
int test3()
{
    int i = 2;
    i++;
    printf("%d",i);
    return 1;
}

int main()
{

    pfCallBack table[]={test1,test2,test3};
    table[0]();
    return 1;
}
#endif
原创粉丝点击