Hey guys, I want to copy my first Array to my second Array in reverse order.
Here is my code (I use Microsoft Visual Studious so the syntax may be different):
void copyArray1(int myArray1[], int myArray2[],
int numOfElements1, int numOfElements2)
{
numOfElements2 = numOfElements1;
for (int i = (numOfElements1 + 1); i >= 0; --i)
{
myArray2[i] = myArray1[i];
}
printArray2(myArray2, numOfElements2);
}
My concern is regarding the for loop. It won't reverse the array. When I do the for loop like this: for (int i = 0; i < numOfElements; ++i), it produces the right output, but when I compile my code that is higlighted bold, it doesn't change. Can anyone help me? Thank you for any help. By the way, I am new to C++ and this forum, so if I didn't pass by refernce or anything like that, can you please correct me? Thanks.
for inverse order you need to invert the index
a[i] = b[i] will just copy each element in the same order, you need to start with the highest and decrease till you reach 0