Answered step by step
Verified Expert Solution
Question
1 Approved Answer
THIS IS THE SECOND TIME I'M POSTING THIS QUESTION BECAUSE I DIDN'T GET A RESPONSE. A RESPONSE IS NEEDED BY 12 pm TODAY. I need
THIS IS THE SECOND TIME I'M POSTING THIS QUESTION BECAUSE I DIDN'T GET A RESPONSE. A RESPONSE IS NEEDED BY 12 pm TODAY.
I need help with the following program. I'm using C++ and vim. It doesn't have to be anything fancy, just one variable for each program. The first picture has the problem, the second picture has the three different types of functions I'm supposed to use. Thanks!
(4 pts) Understand Pointers/Dynamic Memory Write 3 different functions in C++ to create memory on the heap without causing a memory leak. Hint: 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 your 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 valgrind %valgrind program-exeStep 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