Write a reverse function that takes an integer array and its length as arguments. Your function should reverse the contents of the array, leaving the reversed values in the original array, and return nothing.
#include<iostream>
using namespace std;
void printArray(int a[], const int n)
{
for(int i=0;i<n;i++)
{
cout<<a[i];
i!=n-1 ? cout<<", " : cout<<"";
}
}
void reverse(int a[], const int n)
{
int reverse[n];
for(int i=0;i<n;i++)
{
reverse[n-1-i]=a[i];
}
a = reverse;
}
int main()
{
int *a,n;
cin>>n;
a = new int[n];
for(int i=0;i<n;i++)
a[i]=0;
a[0]=1;
reverse(a,n);
printArray(a,n);
delete [] a;
a = NULL;
return 0;
}
After calling reverse function the array from main is not modifying, please advice! :(
newis used here as well. I missed that.using namespace stdis present.