我在我的一个测验中遇到过这个问题。
下面是哪些(是)有效的函数指针声明?选择所有适用的选项。
A、void* f(int);
B、int (*f)();
C、void (*f(int , void(*)(int)))(int);
D、void (*(*f)(int))();
对我来说,我会选择最后都有一对括号的所有东西。但我不确定C和D.
答案 0 :(得分:2)
根据http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html
上的“左右”规则A、void* f(int); f is a function taking an int para that returns a pointer to void
B、int (*f)(); f is a pointer to a function that takes no (as it's c++) para and returns int
C、void (*f(int , void(*)(int)))(int); f is a function that takes an int and a function pointer as parameters, returning a pointer to a function that takes an int as para and returns void
D、void (*(*f)(int))(); f is a pointer to a function that takes an int as para and returns a pointer to a function that take no para and returns void.
所以B和D是你的答案