Home > Back-end >  incompatible pointer type in making 2D array struct in C
incompatible pointer type in making 2D array struct in C

Time:06-19

I'm trying to make 2D array struct in C like this in main function.

function_1(struct example** ex){}
void main(){
    struct example ex[num_1][num_2];
    function(ex);
}

But gcc keep telling me that type of ex and struct example** ex is different. How can I solve this error?

CodePudding user response:

I edited my original answer:

You could instead write

function_1(struct example (*pex) [num_1][num_2]){}
void main(){
    struct example ex[num_1][num_2];
    function(& ex);
}

at least if you know num_1 and num_2 at compile time.

  • Related