Professional Documents
Culture Documents
Dynamic Memory Allocation
Dynamic Memory Allocation
But if we need to allocate memory at runtime me must use new operator followed by data type.
If we need to allocate memory for more than one element, we must provide total number of
elements required in square bracket[ ]. It will return the address of first byte of memory.
delete ptr;
//deallocte memory for one element
delete[] ptr;
//deallocte memory for array
#include<iostream.h>
#include<conio.h>
void main()
{
int size,i;
int *ptr;
delete[] ptr;
//deallocating all the memory created by new operator
Output :