#include <iostream>
using namespace std;
int *arrExpand(int *arr, int arrSize)
{
int *p = new int [arrSize * 2];
for(int i =0; i < arrSize * 2; i++)
{ if(i < arrSize)
p[i] = arr[i];
if(i > arrSize)
p[i] = 0;
}
return p;
}
int main()
{
int mySize = 5;
int myArr[5] = {1,2,3,4,5};
cout << "Array: ";
for(auto v: myArr)
cout << v;
for( int i = 0; i < mySize * 2; i++)
cout << endl << *(arrExpand(myArr,mySize)+i);
//return is not assigned == delete not needed?
return 0;
}
Does the function delete and deallocate the memory since the return is not assigned? Does the memory need to be deallocated?