c_cpp c中的基本函数指针示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp c中的基本函数指针示例相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#include <stdlib.h>


//c function pointer example

int addInt(int n, int m);

int addInt(int n, int m) {
    return n+m;
}


int main() {
    int (*functionPtr)(int,int);
    functionPtr = &addInt;
    int sum = (*functionPtr)(2, 3);
    printf("The sum is %d", sum);
    //The sum is 5
    return 0;
}

以上是关于c_cpp c中的基本函数指针示例的主要内容,如果未能解决你的问题,请参考以下文章