I'm trying to pass an array as a parameter using this function. In the function, I let the user enter how big the array is, as well as the values in said array. What I can't figure out is how to declare the variables in main that will allow me to use the function in main, and more specifically, how do I declare the array variable in main without knowing the size beforehand (user enters size in function).
void arrayFunction(int array1[], int arraySize);
int main() {
int arrayLength;
int arrayMain[];
cout << "Enter length of array: " << endl;
cin >> arrayLength;
arrayFunction(arrayMain, arrayLength);
return 0;
}
void arrayFunction(int array1[], int arraySize)
{
cout << "Enter length of array: " << endl;
cin >> arraySize;
for(int i = 0; i < arraySize; i++)
{
cout << "Enter value #" << i + 1 << endl;
cin >> array1[i];
}
}