As far as I know, the stack is a region in RAM that stores local variables created by each function (including the main() function). The stack is a "LIFO" (last in, first out) data structure that is managed and optimized by the CPU quite closely. Every time a function declares a new variable, it is "pushed" onto the stack. Then every time a function exits, all of the variables pushed onto the stack by that function, are freed (that is to say, they are deleted). Once a stack variable is freed, that region of memory becomes available for other stack variables.

So consider the following code sample:
Code:
#include <stdio.h>


double multiplyByTwo (double input) 
{
  double twice = input * 2.0;
  return twice;
}


int main (int argc, char *argv[])
{
  int age = 30;
  double salary = 12345.67;
  double myList[3] = {1.2, 2.3, 3.4};


  printf("double your salary is %.3f\n", multiplyByTwo(salary));


  return 0;
}
How would the variables shown above be added to the stack and which is the last that goes? From what I know, the variables in int main are pushed on to the stack first since main() is where the program starts. But which variable does first, then is pushed out? Do the variables in multiplyByTwo() go last?