C++ Programming: The Ultimate Beginners Guide to Effectively Design, Develop, and Implement a Robust Program Step-by-Step by Mark Reed

C++ Programming: The Ultimate Beginners Guide to Effectively Design, Develop, and Implement a Robust Program Step-by-Step by Mark Reed

Author:Mark Reed [Reed, Mark]
Language: eng
Format: azw3
Published: 2020-05-10T16:00:00+00:00


To know whether the block of memory allocation fails, you can detect the failure through checking whether the pointer variable is null.

Avoiding Memory Leaks

When a programmer creates a memory in the heap and forgets to delete it, it creates a memory leak. To avoid having a memory leak, you should free the memory allocated on the heap when no longer needed. Always make sure to use the right operator (delete or delete []) to deallocate the memory.

If there is a memory leak, then the memory usage increases. This makes the limited memory resource very costly thus creating more problems later. The example below is a program to show a memory leak.

Syntax

#include <iostream.h>



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.