Home > Enterprise >  char * (*name)[2] as a function parameter
char * (*name)[2] as a function parameter

Time:12-02

I was given a function that I have to fill out and it has these input parameters:

char * replace( const char * text, const char * (*word)[2] )

From my understanding, the function should return a string and is given a string in the first parameter.

The second parameter is an array of subarray that each have 2 strings if I'm not mistaken, but what is the meaning of the *(*name)[2], what is the difference between that and **name[2] And how would I call this array in the function?

EDIT: How do I use this array in the function?

CodePudding user response:

word is a pointer to array 2 of pointer to const char (1 address), while const char **word2 is an array of 2 pointer to pointer to const char (2 addresses):

int main() {
    const char *words[] = { "hello", "world" };
    const char *(*word)[2] = &words;
    const char **word2[2] = {
        &words[0],
        &words[1]
    };
}

Your 2nd question, "how to do I call this array", does not make sense. You use an array (see above) and call a function:

char *result = replace("hello world", word);
  • Related