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.

ネロク
  • 21,268
  • 3
  • 51
  • 67

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,164
  • 2
  • 17
  • 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,225
  • 2
  • 16
  • 26