I found codes that uses address operator to address. See below example codes.
int arr[4] = { -1, -1, -1, -1 };
int arr2[4] = { 0, 0, 0, 0 };
memcpy(arr, &arr2, sizeof(arr2)); // & operator to arr2
When I check values of (arr, &arr) with printf, both addresses are equal.
And I have no idea why this codes are valid. (I'm using C++ 14)
&arr2is the address of the array as a whole.arr2by itself decays to the address of the array's first element. It so happens that the array and its first element are located at the same address.arris the same as&arr[0], and has the typeint *. Same when using plainarr2. But&arr2is a pointer to the array itself, and will have the typeint (*)[4], which really is incompatible with the typeint *. With that said, both&arr[0]and&arr"luckily" happens to be the same location.int arr[](or even using a size likeint arr[4]) is treated asint *arr. If you then use the pointer-to operator on the argument variable, you will get a pointer to that variable (which have the typeint **), not to the original array.std::array(as instd::array<int, 4>). Otherwise usestd::vector. This will solve a lot of problems you might encounter when using plain C-style arrays.