Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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