Chad said:
a stack is a common array of memory where is defined the functions push()
and pop() [and descrive what the functions do]
And what happens if someone changes the array to say a singly linked
list?
I didn't respond to the original question because it was an obvious
troll, but I think you're actually trying to learn something, so ...
The term "stack" has two distinct but related meanings. (Actually it
has more than that, but only two are relevant here.)
In computer science terms, a stack is a data structure with last-in
first-out behavior. In other words, the available operations are
"push', which adds a new element to the stack, and "pop", which
removes the most recently added element (and either gives you its
value or discards it). The first element added to an empty stack
is at the "bottom" of the stack; the most recently added element
is at the "top".
There are a number of ways to implement a stack. One is as a
contiguous chunk of memory, an array, with an index variable that
indicates where the current "top" of the stack is (the bottom is
fixed and doesn't need an index variable). If the array is of a
fixed size, then the stack can only hold at most a fixed number of
elements; pushing an additional element causes an overflow error,
which must be handled somehow; conversely, if you use only a small
portion of the array, the rest is wasted. Another way to implement
a stack is as a linked list, which avoids the overflow and waste
problems (until you run out of memory), but is a bit more complex
and probably slower.
The other common meaning of "stack", usually referred to as "the
stack", is in computer systems architecture. It's a contiguous
region of memory where the index variable indicating the current
"top" of the stack is typically a CPU register, the stack pointer
(often called the "SP" register). Many systems use such a stack to
implement function calls: all the information needed for a function
call, including local data, possibly parameters, and housekeeping
data such as the return address, is pushed onto "the stack" when a
function is called, and popped when the function returns. The stack
may grow either up or down in memory, depending on the system.
Most current systems use this kind of stack, but not all do, and the
C standard doesn't refer to it at all. There are systems that use a
linked list of activation records, rather than a contiguous stack,
to manage function calls. There have been systems that don't use
any kind of stack for function calls; such systems cannot directly
support recursion, and therefore cannot support a C implementation.
Even on systems that do use a contiguous hardware stack, the details
vary from one system to another. Unless you're dealing with very
low-level details, you don't need to know about how the hardware
stack works to understand how a C program works.
I'm going into all this gory detail because some people in this
newsgroup have (perhaps deliberately) confused the two concepts,
and others have refused to acknowledge that a C implementation can
possibly use anything other than contiguous hardware stack.
Don't let them confuse you..