I understand hoew a stack works but my question is, How is a stack used in a real programming situation? If you can give me an example (not code). If you wrote a operating system like Windows 2000, what does the stack code do in the program?
I understand hoew a stack works but my question is, How is a stack used in a real programming situation? If you can give me an example (not code). If you wrote a operating system like Windows 2000, what does the stack code do in the program?
It can be used in game programming. Say for example you had a deck of cards. You would impliment a stack and deal the top card until the stack was empty.
Regarding OS's. I know that there is a memory function stack that stores variables. When the scope of the function terminates than the variables are released from the stack. Operating sytem internals is a big subject:
Book:
Inside Windows 2000 Thrid edition by Solomon and Russinovich
Every c function you write most likely pushes args on the stack and then pops the stack. On intel chips the call and later ret works by storing the address of the function on the stack. Any other way would probably make recursion hard to implement.
compilers also use em to evaluate expressions.
A recursive function uses it to save to values of the parameters given to a particular instance....and other vars tooo....