new returns a pointer, so you have to change
int b[] = new int[elements];
to
int* b = new int[elements];
and you should just delete pointerand just return b, therefore
int* reverseArray (int a[] ,int elements)
{
int x = elements-1;
int* b = new int[elements];
for (int i = 0; i < elements; ++i)
b[i] = a[x--];
return b;
}
But you really have to use std::vector. If you use std::vectorto cancel an array, you can just use std::reversefrom <algorithm>.
source
share