Hi. can someone tell me why the following is correct and will compile:
int static_Array[5];
dynamic_Array = new int[5];
dynamic_Array = static_Array;
but the opposite:
static_Array = dynamic_Array will not compile.
dynamic_Array is a int*, right? You can change the pointer to point to some other data. static_Array is an array, not a pointer, so you cannot make it point anywhere.
Static arrays are constant pointers, so they can't be changed! Dynamic arrays on the other hand are plain pointers, with extra memory put aside. Const-pointers can be assigned to regular pointers, but nothing can be assigned to const-pointers!
Static arrays can be implicitly cast to constant pointers, but they are not pointers themselves, they are arrays. It's treated as a different type by the langauge (as can be seen via passing arrays to a function by reference... or, more commonly, with sizeof)