When exactly do you use dynamic memory instead of just instantiating an object of a class? The tutorial from here http://www.cplusplus.com/doc/tutorial/dynamic/
indicates that when using an array where the size is determined during runtime, it can be used. I understand this, but there are many other cases when this is used where it's not an array but just a single instance.
What is the advantage of using "new" operator for dynamic memory allocation and is there some sort of a guideline to when it is used?
Also, there may be times when you will want to create a new object inside a function, and return a pointer or handle to the newly-allocated memory. Any number of Windows API functions, such as CreateWindow(), CreateSolidBrush(), etc., use this method. You have to make sure you free the memory later by yourself in most cases, but if you didn't use dynamically-allocated (heap) memory, whatever you created inside the function would be automatically be freed when the function went out of scope.