Stack vs. Heap

Consider the pros and cons of allocation on stacks vs. heaps when creating variables.

We can choose to allocate space for a variable explicitly on the heap instead of the stack depending on our needs. To write effective code, the pros and cons for each type of allocation should be kept in mind.

Pros and cons