Forgot password?
 Create new account
View 101|Reply 0

an array of three function pointers

[Copy link]

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2022-8-28 20:21:25 |Read mode
讨论区遇到这样的一道题:
What is x in the following program?
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     typedef char (*(*arrfptr[3])())[10];
  5.     arrfptr x;
  6.     return 0;
  7. }
Copy the Code

答案是x is an array of three function pointers
参考Return array from function in CC - 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.

如果举个例子就好了
  1. #include<stdio.h>
  2. typedef char(*(*arrfptr[3])())[10];
  3. char arr[10];
  4. char(*F())[10] { return &arr; }
  5. arrfptr x = {&F,&F,&F};
  6. int main() {
  7.         return 0;
  8. }
Copy the Code
运行成功,无报错
解释:
char arr[10]    ⟶    arr是10个字符的数组
char(*F())[10]    ⟶    F是函数,返回类型为“10个字符的数组”的指针
char(*(*x[3])())[10];    ⟶    x是3个“返回类型为‘10个字符的数组的指针’的函数”的指针的数组

手机版Mobile version|Leisure Math Forum

2025-4-20 22:13 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list