Simple Dynamic Memory Allocation demonstration in C++
#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; }
The Sum of 10 and 20 is 30
Comments :