I am needing help with programming challenge problem 12. It will compile, however, its does not make the array twice the size of the argument array. The problem says:
Write a function that accepts an int array and the array's size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and intialize the unused elements of the second array with 0. The function should return a pointer to the new array.
This is what I have so far:
//This program is used to accept an int array and the array's size as arguments, and then creates a new
//array that is twice the size of the argument array.
#include
using namespace std;
int* expandSize (int*, int);
int main()
{
const int SIZE = 10; //Number of elements
int ary [SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; //Used to hold numbers
int* num = ary;
for(int index= 0;indexcout<
num = expandSize(ary, SIZE); //Used to assign num to the memory location of the return
for(int index=0;indexcout<
delete[] num; //Used to delete memory
num = 0; //Used to point the unused elements of the second array with zero.
return 0;
}
//**********************************************************************************************************
//The function expandSize accepts an int array and the array's size as arguments. The function then creates*
//a new array that is twice the size of the argument array. *
//**********************************************************************************************************
int* expandSize(int* arr, int size)
{
int* expandArray=new int[size * 2];
for (int index=0;indexexpandArray[index]=arr[index];
for (int index=size;indexexpandArray[index]=0;
return expandArray;
}