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
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