函数指针作为参数 [英] Function pointer as an argument

查看:118
本文介绍了函数指针作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过一个函数指针在C参数传递给函数?

Is it possible to pass a function pointer as an argument to a function in C?

如果这样,我将如何声明和定义一个函数,它接受一个函数指针作为参数?

If so, how would I declare and define a function which takes a function pointer as an argument?

推荐答案

肯定。

void f(void (*a)()) {
    a();
}

void test() {
    printf("hello world\n");
}

int main() {
     f(&test);
     return 0;
}

这篇关于函数指针作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆