A simple way to interpret complex declarators is to read them “from the inside out,” using the following four steps: Start with the identifier and look directly to the right for brackets or parentheses (if any).
Interpret these brackets or parentheses, then look to the left for asterisks.
If you encounter a right parenthesis at any stage, go back and apply rules 1 and 2 to everything within the parentheses.
Apply the type specifier.
char *( *(*var)() )[10];
^ ^ ^ ^ ^ ^ ^
7 6 4 2 1 3 5
In this example, the steps are numbered in order and can be interpreted as follows: The identifier var is declared as
a pointer to
a function returning
a pointer to
an array of 10 elements, which are
pointers to
char values.
Interpret these brackets or parentheses, then look to the left for asterisks.
If you encounter a right parenthesis at any stage, go back and apply rules 1 and 2 to everything within the parentheses.
Apply the type specifier.
char *( *(*var)() )[10];
^ ^ ^ ^ ^ ^ ^
7 6 4 2 1 3 5
In this example, the steps are numbered in order and can be interpreted as follows: The identifier var is declared as
a pointer to
a function returning
a pointer to
an array of 10 elements, which are
pointers to
char values.
从标识符开始,直接在右边寻找方括号和圆括号(如果有的话).解释这些方括号和圆括号,
然后在左边寻找星号.在任何阶段你遇到一个圆括号,返回并对所有在圆括号里的东西,应用规则1和2.
应用类型区分符char *( *(*var)() )[10];
^ ^ ^ ^ ^ ^ ^
7 6 4 2 1 3 5在这个例子里,这些步骤用数字编号,能解释如下:
变量被声明为:
var被声明成为一个函数的指针的指针的数组,这个数组有10个元素,函数的原型为带一个char类型的参数,返回值为一个指针
1.以标识符开始,然有 径直向右寻找括号(如果有的话)。
2.解释这些括号或者参数,然后向左寻找星号.
3.如果你在任何情况下都遇到一个右面的括号,回溯应用规则1和规则2到参数中的每一个.
4.应用这个类型说明符.char *( *(*var)() )[10];
^ ^ ^ ^ ^ ^ ^
7 6 4 2 1 3 5
例子中,步骤被按序标识,可以被如下解释:这个表示符变量被声明为一个函数指针,这个函数也返回一个指针,这个指针指向一个有十个元素的数组,数组元素都是指向char类型的指针。
^ ^ ^ ^ ^ ^ ^
7 6 4 2 1 3 5
块解析分析方法:
1。*(*var)(),
很明显这个大家都知道,定一个var函数指针,参数为void,返回一个指针(暂时不看返回的指针类型)2。char *( )[10];
很明显是个指针数组嘛,3。char *( *(*var)() )[10];
OK,整体分析,返回的是一个指针(注意了返回的指针类型),指向一个char[10]的指针(即指向一个大小为10的数组,数组的内容是char)