C++ tutorial-C++ memory management


C++ memory management

new and delete operators


The new operator is used to allocate memory. It returns a pointer to the address of the newly allocated memory.

Example:

int *i;
i = new int;
*i = 5;

The delete operator deallocates memory that was allocated.

Example:

int *i;
i = new int;
*i = 5;
delete i;



Comments

Troy comment

 Troy

for more C++, C exercises,
please visit http://ccphplusplus.blogspot.com/


2015-05-26



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.