-6

我在一次测验中遇到了这个问题。

下面哪个是有效的函数指针声明?选择所有符合条件的。

A、void* f(int);
B、int (*f)();
C、void (*f(int , void(*)(int)))(int);
D、void (*(*f)(int))();

对我来说,我会选择最后有一对括号的所有内容。但我不确定C和D。

4

1 回答 1

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是你的答案

于 2013-10-10T14:17:17.923 回答