Question: Write 3 different functions in C++ to create memory on the heap without causing a memory leak. You will need to assign the address to

 Write 3 different functions in C++ to create memory on the

Write 3 different functions in C++ to create memory on the heap without causing a memory leak. You will need to assign the address to a pointer that was created outside the function. Remember, you can return an address or change what a pointer points to (the contents of a pointer) in a function by passing the pointer by reference or by passing the address of the pointer. What if you want to change the contents of what the pointer points to? Make a function that will set the contents of the space on the heap. Do you still need to pass by reference or the address of the pointer? Why or why not? How will you delete the memory off the heap? Try doing it outside a function, now inside a function. Make sure you delete function is setting your pointer back to NULL, since it is not supposed to be pointing anywhere anymore. You can check to see if you have any memory leaks using Val grind. % Val grind program_exe

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!