回调函数

#include <stdio.h>
#include <string.h>

typedef int FuncType(int,int); 

int Add(int a,int b)
{
    return a + b;
}

int Sub(int a,int b)
{
    return a - b;
}

void Run(FuncType* pf,int a,int b)//回调函数是使用函数指针作为参数
{
    printf ("result = %d
",pf(a,b));
}

int main(void)
{
    int a,b;
    scanf ("%d%d",&a,&b);

    char str[5];
    scanf ("%s",str);

    if (0 == strncmp("add",str,3))//判断输入的字符与add是否一致
  { Run(Add,a,b); }
if (0 == strncmp("sub",str,3))
  { Run(Sub,a,b); }
return 0; }
原文地址:https://www.cnblogs.com/xiaozoui11cl/p/13228427.html