I've been searching through past discussions on this topic and I understand that arrays need to have a constant value, but I'm assigning it a constant value through a variable, and it is not working. I need help with this logic. The problem I believe is in my function declaration. The Error messasge is"Expression must have a constant value." Here's the code...
// Jason Delgado
// 10/13/16 ©
// Chapter 9: Array Expander
// This program has a function that doubles the size of an array.
// It copies the contents of the old array to the new array, and
// initializes the unused elements to 0. The function then
// returns a pointer to the new array. Pointer notation
// must be used for the function, and within the function.
#include <iostream>
using namespace std;
// Function protoype
int *arrExpander(int[] , int);
int main()
{
// Create and initialize and array.
const int SIZE = 6; // Number of elements the array is to hold
int oArr[SIZE] = { 10, 28, 34,
5, 18 }; // The original array
int *nArr = nullptr; // A pointer to hold the return value of the function.
// Call the arrExpander function and store it in nArr.
nArr = arrExpander(oArr, SIZE);
// Display the results
cout << "Original Array: ";
for (int count = 0; count < (SIZE); count++)
cout << oArr[count] << " ";
cout << "\n\nNew Array: ";
for (int count = 0; count < (SIZE * 2); count++)
cout << *(nArr + count) << " ";
system("pause");
return 0;
}
int *arrExpander(int arr[], int size)
{
int *ptr = arr;
const int DSIZE = size * 2; // Doubles the size parameter
int newArray[DSIZE];
}