Try the fastest way to create flashcards
Question

When a program is finished with a chunk of dynamically allocated memory, it should free it with the __________ operator.

Solutions

Verified
Answered 6 months ago
Step 1
1 of 2

The delete operator is used to free memory space which was allocated dynamically, it has big importance to make efficient use of memory by releasing that space to be reused as it is not needed anymore.
It has the following syntax,

/*
// release single variable
delete ptrName;
//release array of variables
delete[] ptrName;
*/
// example
char *cPtr = new char;
// allocating array of 10 integers dynamically
int *ptrArr = new int[10]; 
// some code ...
delete   cPtr;
delete[] ptrArr;  // dynamically allocated space must be
                  // deleted, or a memory leak would happen

NOTE: memory leak happens when there is a dynamically allocated space that is not needed and/or could not be accessed anymore, so that such space consumes our resources in a useless manner, which may make your program crash.

Create a free account to view solutions

Create a free account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263 (6 more)David A. Patterson, John L. Hennessy
226 solutions
Starting Out with C++: Early Objects 8th Edition by Godfrey Muganda, Judy Walters, Tony Gaddis

Starting Out with C++: Early Objects

8th EditionISBN: 9780133360929 (4 more)Godfrey Muganda, Judy Walters, Tony Gaddis
844 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (3 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions

More related questions

1/4

1/7