InterviewSolution
Saved Bookmarks
| 1. |
Explain memory leak in C++. How can you avoid it? |
|
Answer» Memory leaking happens in C++ when programmers dynamically allocate memory with the new keyword or using malloc()/calloc() and then forget to deallocate it with the delete() or delete[] operators or the free() function. In C++, one of the most common causes of memory leakage is the use of the incorrect delete operator. The delete [] operator should be used to free an array of DATA values, whereas the delete operator should be used to clear a single allocated memory space. To avoid memory leak:
|
|