Refer the sample Here
It is the memory segment where
almost everybody declares and uses the variables. When you declare a variable
inside the function that goes to the stack segment of the memory.
All the stack segments wiped out once you go out of the function and when you
come inside the some other function a new stack segment for that function is
created. So this is a less costly segment as it lives till corresponding
function returns back to the caller.
Let us assume Program main
calls the function A. Here first the Stack Segment for Main is
created, then when you are inside the function A, main programs
stack segment becomes un-accessible and at the same time stack segment for Function
A is created. When the function A return the control to main program,
stack segment for A is cleared and stack segment for program main (Still lives,
it became temporarily un-accessible) becomes available. You can refer my
previous post for detailed example about stack segment.
In our example the below two
statements in the main is created in stack segment:
//MemSeg04: Declare a loval variable and declare
a pointer and store the address of local variable
int
m = 12;
int*
pm = &m;