Needs help with how to allocate memory in c++. Used - paintValues = new int [intSize] but gets error 2) Make a procedure called MakeArray that takes two parameters by reference: palngValues, IngArraySize. In the procedure prompt the user to enter a size. The size must be from 1 to 100. Loop until a valid size is entered. Allocate an array of the size specified, initialize it and assign it to the pointer passed in. Call this procedure from main.
Explanation / Answer
Try this code: #include using namespace std; //Function takes one int pointer by reference and an integer by reference void MakeArray(int *&paIngValues, int &IntArraySize) { coutIntArraySize; //Check validity of size while(IntArraySize < 1 || IntArraySize > 100) { coutIntArraySize; } //Allocation of array of size IntArraySize int *array = new int[IntArraySize]; //Initializing all array elements to 0 for(int i = 0; i