Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Array Assignment

Tags:

c

i don't know where is the problem i'm assigning the address to other 2 dimensional array. Please help me to fix this problem

int main()
{
    int a[3][2];
    int b[2]={0,1};
    a[2]=b;
    return 0;
}

prog.cpp:8:9: error: invalid array assignment

like image 610
Rohit Mangla Avatar asked Oct 15 '25 05:10

Rohit Mangla


1 Answers

You can't copy an array using =. Neither can you assign an array's address; x = y; doesn't work either when x and y have types char[1] for example. To copy the contents of b to a[2], use memcpy:

memcpy(a[2], b, sizeof(a[2]));
like image 53
cadaniluk Avatar answered Oct 17 '25 19:10

cadaniluk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!