I have an array A [8] = {0}; And another array B[20] = {0};
I want to move all the values from B[12...20] to A[0...8]. How can i exactly change the indices? is there a formula? So B[12] -->A[0] B[13] -->A[1]
Thank you.
Use std::copy. It works for user defined types too:
std::copy(B+12, B+20, A);
or, in c++11,
std::copy(std::next(B,12), std::end(B), std::begin(A));
You should use std::copy here, which will work correctly no matter the type of elements in your arrays (speaking of which, you don't show that type -- the question has invalid syntax).
std::copy(B + 12, B + 20, A);
memcpy(A, B + 12, 8 * sizeof(A[0])); should do the trick.
Assuming A and B are both the same type.
std::copy answer from Jon, since you are using C++.
B[20]is out of bounds. You probably meanB[12...19].