There are a couple notes to keep in mind when reading complex declarations:
[]
and ()
) operators, which appears to the right of a variable, take place over the *
operator.Some examples:
int *ptrs_to_ints[5] /* An array of 5 pointers to ints */
int (*ptr_to_array)[5] /* A pointer to an array containing 5 ints */
int *(*pts_to_ptrs)[5] /* A pointer to an array of 5 pointers to ints */
A helpful algorithm to follow comes from here:
However, strictly thinking in terms of these steps is probably only really necessary when you come across something like this:
char *( *(*var)(int) )[10];
This can be read as “var is a pointer to a function taking in an int and returning a pointer to an an array of 10 pointers to chars”. Most more commonly seen declarators will be easier to understand. For another algorithm of interpreting the most complex declarator, see the spiral of death.