Stack vs Heap

The Stack

What is the stack? It’s a special region of your computer’s memory that stores temporary variables created by each function (including the functionmain()). The stack is a “LIFO” (last in, first out) data structure, that is managed and optimized by the CPU quite closely. Every time a function declares a new variable, it is “pushed” onto the stack. Then every time a function exits, all of the variables pushed onto the stack by that function, are freed (that is to say, they are deleted). Once a stack variable is freed, that region of memory becomes available for other stack variables.

Continue reading “Stack vs Heap”