How do I dynamically expand my array? Here is the code I have now.. After this f
ID: 3595135 • Letter: H
Question
How do I dynamically expand my array? Here is the code I have now.. After this function runs, I want to prompt the user how many numbers theyd like to append to the array, and then they will be prompted each number with the same process below.. (C++)
void myArray::arrayNums(int *point, int size, int temp)
{
cout << "Amount of numbers you would like in your array: ";
cin >> size;
cout << " ";
int *pointer = NULL;
point = new int[size];
for (int counter = 0; counter < size; counter++)
{
cout << "Enter your number " << counter + 1 << ": ";
cin >> temp;
*(point + counter) = temp;
}
cout << " Here is your array: " << endl;
for (int counter = 0; counter < size; counter++)
{
cout << "arr[" << counter << "] = " << *(point + counter) << endl;
}
}
Explanation / Answer
Or You can use a dynamic container such as vectors.
Please do give a thumbs up and leave a nice comment too.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.