Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here's an assignment that will give you a chance to try dynamic memory management! The program will let the user indicate the dimension of an

image text in transcribed

Here's an assignment that will give you a chance to try dynamic memory management! The program will let the user indicate the dimension of an array of integers, which is allocated from the heap. The array elements will be set to defined values and displayed to stdout before being released back to the heap. There are three functions involved here: main. Allocints and DispArray. Here's what each function should do: main - Ask the user how many ints to allocate for the array and get the value into a local variable. Then, pass the number of ints value as an argument to the AllocInts function; this function will allocate the array and return a pointer to the caller (which is main), so be ready to catch the return value into another local variable! Once the array is allocated, pass the base address of the heap array along with its dimension as arguments to the DispArray function, which will display it to the screen. After the array has been displayed, release the dynamic array from the heap. AllocInts - This function will receive the number of ints to allocate from the caller. Use the new operator to allocate the array and save the base address in a local pointer. Then assign sequentially increasing values to each array element (e.g., 1.2, 3.4.5. etc) Once that's done, return a pointer to the array to the caller. DispArray This function receives as input the base address of an array and the number of elements in the array. All you have to do here is display the array to out before returning to the caller. If you want more information about how to use the new and delete operators, look in your textbook on p512. As far as dynamic arrays are concerned, he discusses those beginning on p521

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

What is the difference between a public key and a private key?

Answered: 1 week ago