New and Delete operator in C++

In C++, the new operator is used to allocate the memory from free store and delete operator is used to return the previously allocated memory back to the free store.


We can say new and delete perform the job of  malloc()(dynamic memory allocation) and free()(perform deallocation) functions(of C)






int main()



     int *pa=new int;

     int *pb=new int;

     int *psum=new int;

     cout<<"Enter the integer values"<<endl;


     cout<<"value of *pa="<<*pa<<endl;

     cout<<"value of *pb="<<*pb<<endl;


     cout<<"sum of integer values are="<<*psum<<endl;

     delete pa;

     cout<<"after deletion *pa="<<pa<<endl;

     delete pb;

     cout<<"after deletion *pb="<<pb;


     return 0;



New and Delete operator in c++