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







©2017 About.com. All rights reserved.