title: local variable in recursive function
body: <p>I writed recursive function named pascal_n to implement Pascal's triangle.
  return type of pascal_n is int * and I declared local variable int * pre_ptr,int *cur_ptr.
  cur_ptr points 1d array cur_arr[MAX].
  But Even in recursive functions, I understanded that local variable disappears when the function ends, but why can I assign a return value (address value) to pre_ptr and access pre_ptr[]? Even if pascla_n returns cur_ptr,cur_ptr points cur_arr,local variable. How does this code work?</p>
  <p>This part</p>
  <p><strong>pre_ptr=pascal_n(n-1);</strong></p>
  <p><strong>cur_ptr[i+1]=pre_ptr[i]+pre_ptr[i+1];</strong></p>
  <p>full code ↓</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  #define MAX 51
  
  int* pascal_n(int n) {
      int prev_arr[MAX];  
      int cur_arr[MAX];
      int *cur_ptr=cur_arr;
      int *pre_ptr;
      int k=0;
      cur_arr[k]=1;
      k++;
      if(n==1){
          cur_arr[0]=1;
          printf(&quot;1\n&quot;);
          return cur_ptr;
      }
      else {
          pre_ptr=pascal_n(n-1);
          for(int i=0;i&lt;n-2;i++){
              cur_ptr[i+1]=pre_ptr[i]+pre_ptr[i+1];
              k++;
          }
      }
      cur_arr[k]=1;
      for(int j=0;j&lt;=k;j++)
          printf(&quot;%d &quot;,cur_arr[j]); 
      printf(&quot;\n&quot;);
      return cur_ptr;
  }
  
  int main() {
    int n;
  
    scanf(&quot;%d&quot;, &amp;n);
    pascal_n(n);
  
    return 0;
  }
  </code></pre>