char *(*c[10])(int **p);

Ok, what does the above mean ? I compiled it fine. But I can't figure what it means :(

Also, how to make sense of any such questions ? I know pointers, and have a concept of it. But this one really baffled me ! Can anyone tell me how to REALLY make sense of other questions of this kind ?

Thank you!
regards
MiniGWeek ( Back ! )

Rashakil Fol commented: Whats up! +8

>char *(*c[10])(int **p);
>Ok, what does the above mean ?
The variable c is an array of ten pointers to functions that take a pointer to a pointer to int as a parameter and return a pointer to char. To read a declaration like this you read it from the inside out:

char *(*c[10])(int **p);
        [B]c[/B]                c
        c[B][10][/B]            is an array of 10
       [B]*[/B]c[10]            pointers
      [B]([/B]*c[10][B])[/B]           to
      (*c[10])[B]()[/B]         functions
      (*c[10])([B]int **p[/B])  that take a pointer to a pointer to int
[B]char *[/B](*c[10])(int **p)  and return a pointer to char

Or you can remove parts that are obviously not important, like the return value and parameters. Replace those with void and you can remove three asterisks that might confuse you:

void (*c[10])(void);

Remember that in declarations like this, parentheses mean something. The parens wrapping *c[10] means that this is the central point. If you take away everything else and just add int to the left, you have an array of pointers to int:

int (*c[10]);

With that in mind, you can then remove the array because it's no longer important. You know that the thing is an array, so now you need to know the type of the array:

void (*c)(void);

This is a classic function pointer declaration. The parens say that c is a pointer. If you remove them, it says that c is a function that returns a pointer to void. Now that you know the underlying type is a pointer to a function, you can add the stuff back to say that c is an array of the underlying type (a pointer to a function):

void (*c[10])(void);

And put back the unnecessary stuff that further specializes what the underlying type does: the parameters and return value:

char *(*c[10])(int **p);

And you're back to the beginning. c is an array of ten pointers to functions that take a pointer to a pointer to int and return a pointer to char.

That's two ways to read a complex declaration in C++.

commented: an outstanding breakdown of the given question. +5

Thanks Narue,
Thats a nice explanation I understood quite nicely.
But I will have to do some reading on my own, to get complete understanding of this.
Interesting explanation...

Bench, that was a helpful link , thank you too..

I will let you know here , if I get myself in a fix regarding this again..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.