title: Calling function twice override the first value C++
body: <p>I am trying to multiply arrays , </p>
  
  <p>the function <em>mul</em>  is matrix multiplication:</p>
  
  <pre><code>    typedef int array2d [3][3];
  
      array2d arr,A,B,C,D,r,s,k;
  
      array2d* mul(array2d r,array2d s)
      {
          for(int i=0;i&lt;3;i++){
            for(int j=0;j&lt;3;j++){
              arr[i][j]=0;
              for(int k=0;k&lt;3;k++){
                arr[i][j]+=(r[i][k] * s[k][j])%31;
                                  }
                               }
                            }
      return &amp;arr; 
  }
  </code></pre>
  
  <p>in the <em>main</em> function I enter A, B C and D values, then I call <em>mul</em>:</p>
  
  <pre><code>  array2d *a1;
      a1 = mul(A,B);
  
  array2d *a2;
      a2 = mul(C,D);
  </code></pre>
  
  <p>Calling first function will return correct values of a1.</p>
  
  <p>But once calling the second function
  , a1 will have the same value of a2. </p>
  
  <p>How can I solve this problem?</p>
  
  <p>Thanks</p>