C语言中的函数指针数组 [英] Array of function pointers in C
本文介绍了C语言中的函数指针数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难理解函数指针的语法.我想做的是,有一个函数指针数组,不带任何参数,并返回一个空指针.有人可以帮忙吗?
I'm having really hard time comprehending the syntax for function pointers. What I am trying to do is, have an array of function pointers, that takes no arguments, and returns a void pointer. Can anyone help with that?
推荐答案
-
首先,您应该了解
cdecl
:
cdecl> declare a as array 10 of pointer to function(void) returning pointer to void
void *(*a[10])(void )
您可以手工完成-只需从内部进行构建:
You can do it by hand - just build it up from the inside:
a
是一个数组:
a[10]
指针:
*a[10]
功能:
(*a[10])
不带参数:
(*a[10])(void)
返回void *
:
void *(*a[10])(void)
如果使用typedef
可以使生活更轻松,那就更好了:
It's much better if you use typedef
to make your life easier:
typedef void *(*func)(void);
然后创建数组:
func a[10];
这篇关于C语言中的函数指针数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文