janus said:
I was not able to carry out the below,
int array1 = {{2,1},{1,0}};
int array2 = {{3, 5},{7,9}};
array2 = array1;
It is better to cut and paste (or similar). Neither array1 nor array2
is declared as an array so your example does illustrate what you were
doing.
I got incompatible type error.
My only saving grace was memcpy... Now, I would want somebody to
explain why array to array copying failed.
There are lots of levels for such an explanation. The simplest is
that C is designed that way: arrays are not "assignable". Another is
slightly more technical: the name of an array is converted to a
pointer to its first element[1] so that both sides of what appears to
be an array assignment are, in fact, pointer valued expressions.
Worse, the one on the left is not a modifiable lvalue -- it is just a
value and you can't assign to such a thing. One could get more
technical still and explain it all in terms used by the language
standard, but I doubt that would help.
There are also other kinds of explanation that would explain why is C
designed this way, but I am not sure I fancy trying that one!
So, in short, C is just like that. You can't assign whole arrays and
you have to use something like memcpy instead.
[1] There are a few exceptions, but lets keep this simple.