CPP Dynamic Constructor

Dynamic Constructor

  • Dynamic constructor is used to allocate the memory to the objects at the run time.
  • Memory is allocated at run time with the help of 'new' operator.
  • By using this constructor, we can dynamically initialize the objects.


#include <iostream.h>
#include <conio.h>
class dyncons
 int * p;
  p=new int;
 dyncons(int v)
  p=new int;
 int dis()
 { return(*p);
void main()
dyncons o, o1(9);
cout<<"The value of object o's p is:";
cout<<"\nThe value of object 01's p is:"<<o1.dis();


The value of object o's p is:10
The value of object 01's p is:9

Share This Page to Download:

Share to Download

Share This Page on:

Ask Question