Difference between Dynamic memory allocation and dynamic objects?

Hello Garima, thank you for the question.

Dynamic memory allocation is when you explicitly assign a memory address to a variable with the new keyword. Any time this is done, a block of memory from the heap is assigned, and it must be cleaned up with the delete keyword, otherwise the memory will be leaked.

int *p = new int;
*p = 4;
cout << *p; // Prints 4
delete p;

A dynamic object is a type of class that can grow and shrink itself as needed. A common example would be a Linked List: http://en.wikipedia.org/wiki/Linked_list. It can grow and remove nodes from itself as to only use enough memory to cover when is stored in it.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.