c++ - How does Stack memory work Or How are function variables allocated and accessed on the stack -


When I read about it on the heap and heap for example, I had a question, for example, On the page, the functions put all their local variables on the stack, does the stack actually use different variables?
Because a stack can usually only reach the top, it will only be able to access one variable of the function. Does this mean that the variable of a function is stored on a stack in a strait?

Stack-pointer, as its name means, an indicator like any other, and This indicates the general standard memory. To access any area of ​​the stack, you add the pointer offset to the normal.

If you think in terms of C-pointers, then you have a stack pointer

  char * Stack_pointer = some_memory;  

This pointer can be used as a normal pointers, in which to connect to offset to reach a specific location on the stat, like

  * (Int *) (StackPoint + 4) = 5;  

I recommend that you try to learn assembler code, then you can create a very simple program with some local variables, and it can be compiled into assembler code and it You can read to see how it works.


Comments