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

1. Array Allocator Write a function that dynamically allocates an array of integ

ID: 3833649 • Letter: 1

Question

1. Array Allocator Write a function that dynamically allocates an array of integers. The function should accept an integer argument indicating the number of elements to allocate. The function should return a pointer to the array. C++ 1. Array Allocator Write a function that dynamically allocates an array of integers. The function should accept an integer argument indicating the number of elements to allocate. The function should return a pointer to the array. C++ 1. Array Allocator Write a function that dynamically allocates an array of integers. The function should accept an integer argument indicating the number of elements to allocate. The function should return a pointer to the array. C++

Explanation / Answer

Here is code:

int* createDynArray(int num)
{
int* dynArray = new int[num]; // create array with size num
return dynArray; // return the array
}

Sample program to test:

#include <iostream>

using namespace std;
int* createDynArray(int num)
{
int* dynArray = new int[num];
return dynArray;
}
int main()
{
int* p = createDynArray(5);

return 0;
}