Explain about new and delete keywords with code
C++ supports dynamic allocation and deallocation of objects using the new and delete operators. These operators allocate memory for objects from a pool called the free store. The new operator calls the special function operator new, and the delete operator calls the special function operator delete.
int* pInt = new int; // allocate memory for one variable int type in heap
int* pIntArray = new int[size]; // allocate memory for several variables int type in heap
delete pInt; // free memomry
delete[] pIntArray; // free memaory
Comments
Leave a comment