Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//Question , how can I make the subscript point to the arraySize //The error is

ID: 3647832 • Letter: #

Question


//Question , how can I make the subscript point to the arraySize

//The error is in the for loop. (arraySize[count] && delete [] arraySize

//Write a function that dynmamically allocates an array of integers.
//The function should accept an intergers argument indicating the number of elements to allocate.
//The function should return a pointer to the array.

#include <iostream>
using namespace std;


int main ()
{
int arraySize; // Holds the array memory
cout << "What is the size of ?";
cin >> arraySize; // point to the array

for (int count = 0; count < arraySize; count++)
{
arraySize[count] = 5*(count +1);
}

cout << " Size of the Array:" << endl;
for (int count = 0; count < arraySize; count++)
{
cout << arraySize[count] << endl;
}
delete [] arraySize;


return 0;
}






Explanation / Answer

Why on earth are you manipulating the base address of the array??? And after this executes the value will be pointing to the last element and then after it if you dodelete [] values; values = 0; //makes elements NULL. It is bound to give errors. Instead do this: //To output the array contents cout