C基础--函数指针

#include <stdio.h>

/*声明一个函数,函数名称的本质就是一个函数指针*/
int funcA(int a, int b)
{
    int c = a + b;
    printf("a = %d, b = %d 
", a, b);
    return c;
}

/*声明一个函数指针*/
/*注意,函数指针的类型要与其指向的函数原型相吻合*/
int (*p_funcA)(int, int);

int(*p_funcB)(int a);

int main(int argc, char** argv)
{
    funcA(3, 9);
    p_funcA = funcA; /*给函数指针赋值*/
    p_funcA(3, 9);  /*通过函数指针调用函数*/

    p_funcB = funcA;  /*类型不匹配,将会引发运行时错误*/

    /*以下写法全都是错误的!*/
    p_funcA = funcA(a, b);
    p_funcA = funcA(int, int);
    p_funcA = funcA(3,7);

    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/zhuyaguang/p/4828026.html