Question: allocateArray This function dynamically allocates memory for the larger array, deallocates the memory of the array being expanded, and returns a pointer to the new

allocateArray This function dynamically allocates memory for the larger array, deallocates the memory of the array being expanded, and returns a pointer to the new larger array. It is invoked to create the initial array, as well as to allocate the new, larger array, copy the items into it, and return a pointer to the calling code. Its details follow: Input parameters: i. A pointer to a dynamic array of integers (the array being outgrown) or NULL/nullptr ii. A pointer to an integer representing the size of the array. Processing and output This function must be able to handle calls to create the initial array, as well as to expand the array. It should be invoked with a NULL pointer initially (there is not yet an array in existence), along with a pointer to the (initial) array size. An array of the requested size should be allocated and returned. In subsequent calls the function should allocate a new, larger array that is 130% the size of the existing array (cast this value to truncate the fractional part). It should also copy the existing data to the new array, deallocate the old array, update the size of the array, and return an integer pointer to the newly allocated array. It must also enforce the maximum array size (500 elements).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!