Professional Documents
Culture Documents
delete operator :
To destroy the variable space which has been created by using the new
dynamically
syntax :
delete pointer; - single variable
ex : delete ptr;
delete []pointer; - for an array
delete []ptr;
Create a memory for 10 integers using NEW operator and
destroy using the delete operator.
#include<iostream.h>
void main()
{
int *ptr,i;
ptr=new int[5];
cout<<endl<<"Enter 5 numbers";
for(i=0;i<5;i++)
{
cin>>*(ptr+i);
}
for(i=0;i<5;i++)
{
cout<<*(ptr+i)<<endl;
}
delete []ptr;
}
Write a C++ program to creates cout<<endl<<"enter the data";
an object of class book and cin>>bno>>author>>bname;
}
destroy it void book::show()
#include<iostream.h>
{
class book
cout<<endl;
{
cout<<bno<<author<<bname;
private :
}
int bno;
void main()
char author[15],bname[20];
public : {
void get(); book b1,*b2;
void show(); b2=new book;
~book() b1.get();
{ b2->get();
cout<<"Destructor called"<<endl; b1.show();
} b2->show();
}; delete b2;
void book::get(){ }