Needs help with how to allocate memory in c++. Used - paintValues = new int [int
ID: 3741973 • Letter: N
Question
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; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.