Its main use is to store local variables, arguments and return address each time a function is called.
When your program calls a function the following happen :
- The function arguments are put on the stack
- The current instruction pointer is put on the stack
- The program jumps to the start of the function
- Space is allocated on the stack to hold local variables
- The function executes
- The space holding local variables is de-allocated
- The instruction pointer is restored and removed from the stack (we are now leaving the function and resuming the calling procedure)
- The arguments are removed from the stack
Chat with our AI personalities
Because the stack pointer marks the top of the stack. If it is not initialised, it is not possible to determine where the next stack frame will go.
what ever you assume
Both of them are pointers, but otherwise they are completely unrelated. The former points to the current position of the stack, the latter points to the current instruction of the program.
A stack is implicitly sorted by hierarchical nested order. It does not make sense to sort a stack. Do you mean a list? If so, please ask the question again.
Two little problems: 1. stack doesn't have a flow-chart 2. there are no flow-charts in a C program