+ 4

Can you explain how call stacks work in detail?

How do call stacks work? Why are they useful in recursion?

18th Mar 2018, 11:56 PM
Julian Aung
Julian Aung - avatar
3 Antworten
+ 9
In computer science, a call stack is a stackdata structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, program stack, control stack, run-time stack, or machine stack, and is often shortened to just "the stack". Although maintenance of the call stack is important for the proper functioning of most software, the details are normally hidden and automatic in high-level programming languages. Many computer instruction setsprovide special instructions for manipulating stacks. A call stack is used for several related purposes, but the main reason for having one is to keep track of the point to which each active subroutine should return control when it finishes executing. An active subroutine is one that has been called but is yet to complete execution after which control should be handed back to the point of call. Such activations of subroutines may be nested to any level (recursive as a special case), hence the stack structure. If, for example, a subroutine DrawSquare calls a subroutine DrawLine from four different places, DrawLine must know where to return when its execution completes. To accomplish this, the address following the call instruction, the return address, is pushed onto the call stack with each call.
19th Mar 2018, 12:16 AM
TrueJu
TrueJu - avatar
+ 3
Thank you for the detailed explanation.
19th Mar 2018, 2:09 AM
Julian Aung
Julian Aung - avatar
+ 3
no problem :)
19th Mar 2018, 11:14 AM
TrueJu
TrueJu - avatar