Junior — Middle
When does memory allocation occur automatically on the stack during program execution?
sobes.tech AI
Answer from AI
Memory allocation on the stack occurs automatically when a function or method is called. When a program enters a new function, a region of memory is allocated on the stack for its local variables and parameters. After the function completes, this memory is automatically freed. Thus, the stack operates on the LIFO (last in, first out) principle, and memory management occurs without programmer intervention.