Answered step by step
Verified Expert Solution
Link Copied!

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

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

What difficulties do virtual teams have in the global environment?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago