I seem to be inventing my own syntax here. The idea seemed simple enough: use the keyword 'new' to allocate space for a new integer array, and populate it with a few integers. Where have I gone wrong?
#include <iostream>
using namespace std;
const int SIZE = 5;
int newArrayMaker();
int main ()
{
int newArray = newArrayMaker();
cout << "The new array has these contents: ";
for (int i = 0; i < SIZE; i++)
cout << newArray[i] << " "; // Error: invalid types int[int] for array subscript
return 0;
}
// Fn def
int newArrayMaker()
{
int *intArrayPointer;
intArrayPointer = new int[SIZE];
if (intArrayPointer == NULL)
{
cout << "Error allocating memory\n";
return 0;
}
for (int i = 0; i < SIZE; i++)
*intArrayPointer[i] = 1;
int newArray = intArrayPointer;
delete [] intArrayPointer;
intArrayPointer = 0;
return newArray;
}