Search code examples
cvariablesstacksegment

which variable parts are stored to the stack in this code?


I have this following code and I don't really understand which variable parts in the test_function are stored onto the stack segment?

In the book it says "The memory for these variables is in the stack segment", so I presume it is when the variables are actually initialized to a value. Right?

void test_function(int a, int b, int c, int d) {
  int flag;       //is it this
  char buffer[10];// and this
                  //or
flag = 31337; //this and
  buffer[0] = 'A'; //this. Or all of it?
}

int main() {
   test_function(1, 2, 3, 4);
}

Solution

  • flag, buffer, and a,b,c,d will be on the stack (well compiler may just remove all the code and call it dead code since it's unused).