Simple Dynamic Memory Allocation in C++

Simple Dynamic Memory Allocation demonstration in C++

Source code :

#include <iostream>

using namespace std;

class dynamic{

	int *a,*b;

public:
	
	void create(){
	    
		a = new int;
		b = new int;
		*a = 10;
		*b = 20;
	}

	void display(){
	    
		cout<<"The Sum of "<<*a<<" and  "<<*b<<" is "<<*a+*b;
		
	}
};

int main()
{
    
	dynamic obj;
	obj.create();
	obj.display();
	
	return 0;
}

Output :

The Sum of 10 and  20 is 30

Output :


                

Comments :