通常,当声明一些变量时,您将其类型放在它之前,如:
int a;
函数指针可能具有类型:int(*)(int,int),以防万一我们指向一个使用两个int并返回int的函数.但是,当声明这样的指针时,它的标识符不在类型之后,如:
int(*)(int,int) mypointer;
相反,您必须在中间写入标识符:
int(*mypointer)(int,int);
为什么这样呢?
对不起,我知道这是一个令人尴尬的简单问题
感谢大家的回复.
如.
解决方法
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 anint
; 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.
原文地址:https://www.jb51.cc/c/113756.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。