|
在讨论区遇到这样的一道题:
What is x in the following program?- #include<stdio.h>
- int main()
- {
- typedef char (*(*arrfptr[3])())[10];
- arrfptr x;
- return 0;
- }
复制代码
答案是x is an array of three function pointers
参考Return array from function in C和C - Array of pointers
讨论:
Gaurav Kumar Garg said: (Jan 19, 2014)
typedef char (*(*arrfptr[3])())[10];
Meaning of this is
arrfptr is array of 3 function pointer which return array of 10 dimension whose type is char.
So,
x is an array of three function pointers.
如果举个例子就好了
- #include<stdio.h>
- typedef char(*(*arrfptr[3])())[10];
- char arr[10];
- char(*F())[10] { return &arr; }
- arrfptr x = {&F,&F,&F};
- int main() {
- return 0;
- }
复制代码 运行成功,无报错
解释:
char arr[10] ⟶ arr是10个字符的数组
char(*F())[10] ⟶ F是函数,返回类型为“10个字符的数组”的指针
char(*(*x[3])())[10]; ⟶ x是3个“返回类型为‘10个字符的数组的指针’的函数”的指针的数组 |
|