Search code examples
c++stackactivation-record

is main () created with an automatic variable, and if so, what's its purpose?


I was reading through my text book in the function call stack section and came across this:

the activation record tells main how to return to the operating system (i.e., transfer to return address R1) and contains the space for main's automatic variable (i.e., a, which is initialized to 10)

this was news to me, so my questions are:

  1. is an automatic variable created?
  2. what is its purpose?
  3. is its value always the same?

thanks in advance


Solution

  • That passage refers to a sample program in your text book. In that sample program, an automatic variable named a is declared and initialized to 10.

    The sample program might look like this:

    int main () {
      int a = 10;
      return 42;
    }
    

    is an automatic variable created?

    Only if you declare one.

    what is its purpose?

    The passage describes ordinary automatic variables that you use in your program, for your own purpose.

    is its value always the same?

    No.