Explain the difference between the stack and the heap. Where are local variables, global variables, and dynamically allocated memory stored?