我如何解释像这样的复杂声明:
int * (* (*fp1) (int) ) [10]; ---> declaration 1
int *( *( *[5])())(); --------> declaration 2
理解上述声明是否应该遵循任何规则?
最佳答案
这是一篇关于如何在 C 语言中阅读复杂声明的精彩文章:http://www.codeproject.com/KB/cpp/complex_declarations.aspx
对我帮助很大!
尤其是 - 您应该阅读“正确的规则”部分。这里引用:
int * (* (*fp1) (int) ) [10]; This can be interpreted as follows:
- Start from the variable name -------------------------- fp1
- Nothing to right but ) so go left to find * -------------- is a pointer
- Jump out of parentheses and encounter (int) --------- to a function that takes an int as argument
- Go left, find * ---------------------------------------- and returns a pointer
- Jump put of parentheses, go right and hit [10] -------- to an array of 10
- Go left find * ----------------------------------------- pointers to
- Go left again, find int -------------------------------- ints.
关于复杂声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1893013/