Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Debug and fix issues C++ #include using namespace std; // Function Prototype int arrayAllocator(int); int main() { int numElements, // To hold the number of
Debug and fix issues C++ #includeusing namespace std; // Function Prototype int arrayAllocator(int); int main() { int numElements, // To hold the number of elements to allocate int pointer = nullptr; // A pointer to the array int i; // A loop counter // Get the array size. cout << " Enter an array size: "; cin >> num; // Allocate the array. pointer = arrayAllocator(numElements); // Fill the array with values. for (i = 0; i < numElements; i+) pointer[] = i; // Display the values. cout << "Here are the values in the array: "; for (i = 0; i < numElements; i++) cout << "Element " << i << " has the value " << pointer[] << endl; // Deallocate the array. delete [] pointer; pointer = nullptr; return 0; } // ******************************************************** // The arrayAllocator function dynamically allocates an * // array of ints. The number of elements is passed as an * // argument into the parameter num. The function returns * // a pointer to the array. * // ******************************************************** int* arrayAllocator(int num) { int *arrPtr = nullptr; // Allocate space for the array. arrPtr = new int[num]; // Return the address of the allocated memory. return arr; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started