The first meaning of stack is a concept that dates back to the time when programmers used punch cards. The stack is a conceptual element of your computer's processor that stores data registers. When you call a function at the asm level, your current operations are suspended and said to be "put on the stack," meaning that they are shelved, but put on top, so that when your current function is done, you will go back to where you were before it started.

Stack is also the name of an STL container with similar behavior. A good analogy for an STL stack is a tower of dimes. It is easy to put a dime on top, read the date off of the top dime, or remove the top dime, but it would be difficult to read the date of the bottom dime, or insert a dime in the middle.

>Also Prelude, I hate to break it to you, but this is the internet,
>and you are an experienced programmer.
Oh! So that's why people keep asking me questions. Whew, it's nice to have that mystery solved.

>Now quit jabbering and get back to work.
What is a stack? A stack is a data structure that is well suited for LIFO type situations where the last item to enter the stack is the first to leave. A good example would be scope levels in a C++ program:

Upon entering main you can consider main to be pushed onto the stack, so it's the only item in our hypothetical example. When the loop is entered, it too is pushed onto the stack because it's a block and has it's own scope. Now you have main at the bottom of the stack and for on top of main. When funcOne is called, it too is pushed onto the stack on top of for. Scope is now in funcOne.

When funcOne returns, it is popped off of the stack because it is no longer needed and the scope returns to for. Just to simplify things, I've set it up so that for is popped when each iteration is finished and pushed when an interation starts (my example, my rules, no?). This process occurs three times, for is pushed, funcOne is pushed then popped, and for is popped. When the third iteration completes and the loop is finished, main returns and is popped from the stack. The program is finished. The life of the stack looks like this:

Code:

f1 f1 f1
for for for for for for for for for
---- main main main main main main main main main main main main main ----

For further illustration please run the program and/or ask for clarification on any point where I was hazy.