Allocating Object In C++
Whenever
we want dynamic memory allocation on object so that time we use new keyword if
that time we want to destroy the memory allocated so we use for delete keyword. This type of object
can do allocation or deletion at same time.
Synatx:
classname
*pointer variable;
pointer
variable=new class name;
Program:
#include<iostream.h>
#include<conio.h>
class
MCA
{
int
a,b;
public:
void
input();
void
output();
};
void MCA::input()
{
cout<<”input
two number”;
cin>>a>>b;
}
void
MCA::output()
{
cout<<a<<b;
}
void
main()
{
MCA
*p;
p=new
MCA;
p->input();
p->output();
getch();
}
No comments:
Post a Comment