1
void recur(int arr[], int l, int m, int r)
 {
   int L[4], R[4];
   // some statements

   recur(/*those arguments*/); //say.
 }

Now if I call the recur() function in recursive way, will L[4], R[4] take same memory address in for every recursion call or it will take different memory address in every call.

JFMR
  • 23,265
  • 4
  • 52
  • 76
  • 1
    To make the question answerable you have to make the function recursive. At the moment your code does not relate to the question you are asking – 463035818_is_not_an_ai Sep 29 '17 at 11:56
  • .. btw you could try it by printing the addresses. Would be hard to prove that they are always the same in this way, but (spoiler) proving that they are not the same is considerably simpler – 463035818_is_not_an_ai Sep 29 '17 at 11:57

2 Answers2

2

The answer is no. Each call to a function (any function) creates a new stack frame with new memory for local variables, regardless of who called the function (the same function or another one). That means different memory addresses.

This answer is true most of the times. However, as cleverly commented, when the last thing the function does is to call itself, most compilers preform a tail call optimization and eliminate the need for all the stacks, using the same stack for all the calls, with different arguments.

Read more here: Stack Frame.

Neo
  • 3,534
  • 2
  • 20
  • 32
1

Considering that it is not Tail Call or Tail Call Optimisation then the short answer is NO. BUT, if it is TCO then YES. Thanks to @lorro for pointing it out!

void recur(int arr[], int l, int m, int r)
 {
   int L[4], R[4];
   // some statements

   recur(/*those arguments*/); //say.
 }

The variables in a recursive DON'T take the same memory address. Each function call creates a new "Activation Record" for the function, which contains it's own stack where stack dynamic variables are stored.

Read more here : Activation Records

Rahul Bharadwaj
  • 2,555
  • 2
  • 18
  • 29