+ 2

When do pointers and dynamic memory come into handy? (C++) Why would we need to store memory? Is the stack worse than the heap?

A code showing it will be helpful (Thanks!)

8th Aug 2017, 7:10 PM
HJ🐓TDM
2 Answers
+ 2
No the stack is not worse than the heap, in fact it's other way around. The stack is faster and more efficient. Dynamic memory comes in handy when you don't know the size of the memory you'll need when compiling. Pointers are for storing addresses of memory locations, such as variables or memory pages
8th Aug 2017, 7:19 PM
aklex
aklex - avatar
+ 2
As Aklex sad,you don't need to use dynamic memory allocation.Using static variables or using stack is faster and mainly more safety;)Dynamic allocation is good to use in case if the size of data for your processing have variable length or if you don't know the length.
8th Aug 2017, 8:35 PM
Highman
Highman - avatar