Question: Rewrite the code to remove the memory leaks, and submit the completed code with a screenshot of the output window with no memory leaks detected.

Rewrite the code to remove the memory leaks, and submit the completed code with a screenshot of the output window with no memory leaks detected.

#define _CRTDBG_MAP_ALLOC

#include

#include

#include

void memLeak()

{

int *p = new int;

char * string1 = new char[20];

char * string2 = new char[25];

strcpy(string1, "Sheldon");

string2=string1;

delete p;

}

int main(int argc, char* argv[])

{

memLeak();

_CrtDumpMemoryLeaks();

return 0;

}

C++ code with no memory leaks:

Screenshot:

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!