Is this correct?
int (*(*ptr)())[];
I know this is trivial, but I was looking at an old test about these kind of constructs, and this particular combination wasn’t on the test and it’s really driving me crazy; I just have to make sure. Is there a clear and solid understandable rule to these kind of declarations?
(ie: pointer to… array of.. pointers to… functions that…. etc etc)
Thanks!
R
The right-left rule makes it easy.
int (*(*ptr)())[];can be interpreted asStart from the variable name ——————————-
ptrNothing to right but
)so go left to find*————– is a pointerJump out of parentheses and encounter
()———– to a function that takes no arguments(in case of C unspecified number of arguments)Go left, find
*———————————————— and returns a pointerJump put of parentheses, go right and hit
[]———- to an array ofGo left again, find
int————————————-ints.