Sunday 25 April 2021

Dynamic Memory Allocation for Variable and Class Object in C++

 #include<iostream.h>

#include<conio.h>

class A

{

 public:


 A()

 {

   cout<<"C-A"<<endl;

 }

 void show()

 {

 cout<<"Show"<<endl;

 }

~A()

{

cout<<"D-A"<<endl;

}

};

int main()

{

clrscr();

{

int *p=new int;  //p is a pointer of type int

*p=5;

cout<<*p<<endl;

float *p1=new float;

float a=10;

p1=&a;

cout<<*p1<<endl;


int *p2=new int(15);

cout<<*p2<<endl;

A *ob=new A;

A *ob1=new A();



}

getch();

return 0;


}

No comments:

Post a Comment