What is the difference between stack and heap allocation?
- A Stack allocation is fast and automatically released at scope exit; heap allocation is slower and must be released explicitly
- B Heap allocation is faster
- C Stack memory is unlimited
- D Heap memory is released at scope exit
Answer
Stack allocation is fast and automatically released at scope exit; heap allocation is slower and must be released explicitly
Prefer the stack. Use the heap only when the object is too large, its size is only known at runtime, or it must outlive the scope.





