I have been working on this code (school assignment) for a few days now. It seems to be almost finished, but I am not sure what's going on.
When I run it in an online complier, it displays correctly, which is supposed to look something like this
"12345"
"1234500000"
However, when I run it in Visual Studio, it's displaying the first number correctly, but instead of 5 zeros, it's coming out with a string of negative numbers.
Any ideas? I appreciate anyone taking the time to look it over or offer any hints.
#include <iostream>
using namespace std;
int *expandArray(int [] , int);
void showArray(int [], int);
int main()
{
const int SIZE = 5;
int array[SIZE] = {1, 2, 3, 4, 5};
int *arrayCopy;
arrayCopy = expandArray(array, SIZE);
cout << "The contents of the original array are: \n";
showArray(array, SIZE);
cout << "Here is the new, expanded array: \n ";
showArray(arrayCopy, (SIZE *2));
return 0;
} //end main
int *expandArray(int arr [], int size)
{
int *newArray = new int [size * 2];
for (int index = 0; index < size; ++index)
newArray[index] = arr[index];
for (int newElem = 10; newElem <(size*2); ++ newElem)
newArray[newElem] = 0;
return newArray;
} // end *expandArray
void showArray(int arr [], int size)
{
for (int index = 0; index < size; index++)
cout << arr[index] << " ";
cout << endl;
} // end showArray