What is Stack vs Heap?
Two memory regions: the stack stores function call data with automatic cleanup, while the heap stores dynamically allocated objects.
The stack is fast, ordered memory that stores local variables, function parameters, and return addresses. It follows LIFO (Last In, First Out) and is automatically managed — memory is freed when functions return.
The heap stores dynamically allocated objects with manual or garbage-collected cleanup. Heap allocation is slower but flexible — objects can live beyond their creating function. Understanding stack vs heap helps optimize performance and prevent memory issues.