Hello, I just started a university course and one of the assignments is to let the user enter in an array, then call a reverse function to reverse the array which sends this array back to the main function, then the main function prints it out.
I can get everything to work except the reverse function as it wont send back an array to the main function. Any help is appreciated.
Thank you
#include <iostream>
using namespace std;
int* reverse (int a)
{
int* z;
int i;
int test [3];
z = test;
for(n=2; n>-1; n--)
{
z [i] = a [n];
i++;
}
return z;
}
In reverse() 'i' is uninitialized. You're changing the value of data outside of the array.
Also the type of the parameter is wrong. Currently it accepts a single int, not an array of them.
By the way there's no need for 'z'. You can change the values directly using test[i] and then return test;.