0

This function:

char ** someFunction(void) {

    static char final[400][2048];

    for(unsigned int i = 0; i < 400; i++) {
        strcpy(final[i], "foo");
    }

    return final;

}

Will get the error:

Incompatible pointer types returning 'char [400][2048]' from a function with result type 'char **'

I thought a char[][] was the same thing as a char**? So why would I an error saying incompatible pointer types?

Any help would be much appreciated.

Ryan Jon Zhang
  • 498
  • 3
  • 12
  • 1
    Look here at [this SO question](https://stackoverflow.com/questions/4470950/why-cant-we-use-double-pointer-to-represent-two-dimensional-arrays) – Icemanind Apr 17 '20 at 02:02
  • 1
    The important lesson here is that arrays are *not* the same as pointers. An array can *decay* to a pointer to its first element, but it's not a pointer. Also, the decay only happens for the "outer" array. That is, your array `final` could decay to a pointer of type `char (*)[2048]`. – Some programmer dude Apr 17 '20 at 02:03

0 Answers0