C函数指针语法

我的问题很简单.

通常,当声明一些变量时,您将其类型放在它之前,如:

int a;

函数指针可能具有类型:int(*)(int,int),以防万一我们指向一个使用两个int并返回int的函数.但是,当声明这样的指针时,它的标识符不在类型之后,如:

int(*)(int,int) mypointer;

相反,您必须在中间写入标识符:

int(*mypointer)(int,int);

为什么这样呢?
对不起,我知道这是一个令人尴尬的简单问题

感谢大家的回复.
如.

解决方法

我在 Why was the C syntax for arrays,pointers,and functions designed this way?的答复中解释一下,基本上归结为:

the language authors preferred to make the Syntax variable-centric rather than type-centric. That is,they wanted a programmer to look at the declaration and think “if I write the expression *func(arg),that’ll result in an int; if I write *arg[N] I’ll have a float” rather than “func must be a pointer to a function taking this and returning that“.

The 07001 claims that:

Ritchie’s idea was to declare identifiers in contexts resembling their use: “declaration reflects use”.

…citing p122 of K&R2.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...