int *(*a[5])(int, char*); 这句C++语句怎么理解?
ringa_lee
ringa_lee 2017-04-17 13:55:19
0
4
538
ringa_lee
ringa_lee

ringa_lee

reply all(4)
Ty80

Your understanding is wrong

int * (*a[5])(int , char * )
a 是一个长度为5的数组, 数组的每个元素是一个函数指针
函数指针的类型
返回值 是 int * , 带两个参数 int , char *

For function pointers

B (*A)(int , char * )
括号外的是函数部分, 括号内的是指针部分

For variables

int *(*a[5]) 其实等同于 int **a[5];

a is an array of length 5, each element of the array is int**

*The order of combination of operators is from right to left. The second * is combined before the first *, so it doesn’t matter whether you need parentheses or not

As for the expression pointer to "pointer array of length 5" (that is, the first row pointer of column length 5 in a two-dimensional array)?
First think about how to express the pointer pointing to {array of length 5}

int  (*a)[5];// 此时的括号才有意义,没括号,[] 优于 * 结合

a points to an array, and each element of the array is int

int* (*a)[5];

a points to an array, and each element of the array is int *

小葫芦

For this kind of problem, the step-by-step decomposition method
int* (*a[5])(int,char*)
can be seen as
int* F(int,char*), where F is equivalent to (*a[5])
hereF It is a function with a return value type of int* and parameter type of (int,char*).
In other words, *a[5] is a function. Because of operator precedence, it can be written as *(a[5]) here.
Then it means that a[5] is a function pointer, pointing to a function of type int*()(int,char*).
So a is actually an array with 5 elements, each element is a function pointer.

伊谢尔伦

a is an array containing 5 elements, each element is a pointer, the pointer points to a function, the function receives two parameters int, char* and returns int*. Simply put, a is an array of function pointers

刘奇

int* (*a[5])(int,char*);

int* (*F)(int, char*) is the definition of function pointer type F. This function takes two parameters (int, char*) and returns int*;
F a[5] is the definition Array a of length 5, whose elements are of type F;

So array a is actually defined, with a length of 5 and a member type of function pointer.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template