Home > SparkCharts > Cs > C++ > Dynamic Memory Allocation

C++


 
 

Dynamic Memory Allocation

During program execution, sometimes it is necessary for a program to allocate additional memory or to dynamically create or destroy objects. Use the new and delete keywords to dynamically allocate memory.

New and delete examples:

int* a = new int; // creates a pointer to a new integer
delete a; // delete memory at a
a = new int [[15]]; // create a new integer array of size 15
delete[[ ]] a; // Delete an array at memory location a