The problem with arrays is that in all expressions (except when passed to the sizeof
and the unary &
operators) they convert to a pointer to their first element.
So, supposing you have:
int arr1[10];
int arr2[10];
...
Then if you write something like
arr1 = arr2;
you are actually attempting to do this:
arr1 = &arr2[0];
or this:
&arr1[0] = &arr2[0];
In both cases you have a problem preventing your code from compiling. In the former case you're attempting to assign between two incompatible types (array vs pointer), while in the latter case you're attempting to modify a constant pointer (&arr1[0]
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…