Search code examples
cfunctionsyntaxdeclarationfunction-declaration

char* (*name())[]; Is this statement array of function pointers?


This statement has made me thinking. I end up with a conclusion function pointer returns the array of character. But I am not able to give proper reasoning to myself.


Solution

  • Read it like this (using Clockwise/Spiral rule):

    char* (*name())[];
    

    1) Find the identifier.

    char* (*name())[];
            ^^^^
    

    "name is a"

    2) Move right.

    char* (*name())[];
                ^^
    

    "name is a function accepting any parameter and returning"

    3) Can't move right anymore because of the right parenthesis, so move left.

    char* (*name())[];
           ^
    

    "name is a function accepting any parameter and returning pointer to"

    4) Can't move left anymore because of the left parenthesis, so keep going right.

    char* (*name())[];
                   ^^
    

    "name is a function accepting any parameter and returning pointer to an array"

    5) Can't move right anymore because we're out of symbols, so go left.

    char* (*name())[];
        ^
    

    "name is a function accepting any parameter and returning pointer to an array of pointers to"

    6) And finally, keep going left, because there's nothing left on the right.

    char* (*name())[];
    ^^^^
    

    "name is a function accepting any parameter and returning pointer to an array of pointers to char".