本文介绍了函数指针作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能通过一个函数指针在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;
}
这篇关于函数指针作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!