title: C the value of an array getting modified sent by pointer after a void function
body: <p>I am currently trying to make moving average with C, and I want to send my address to the function and calculate the moving average inside the function. However, whenever I get out of the for loop inside the function, the pointer which was originally pointing at the initial array changes and I have no idea how to solve the problem. Here is my code: </p>
  
  <pre><code>include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #define n 10
  void monAvg(const float *in, float *out, int m);
  
  int main(int argc, char *argv[]) 
      {   
      float table_in[]={1,2,3,4,5,5,4,3,2,1};
      float table_out[]={0};
  
      if (argc != 2) {
        printf ("Incorrect number of program arguments");
        return 0;
      }
  
      if (atof(argv[1]) &lt; 1 || atof(argv[1]) &gt; n)) {
          printf ("Invalid program argument value");
          return 0;
      }
  
  
      monAvg(table_in, table_out, atof(argv[1]));
  
      return 0;
  }
  
  void monAvg(const float *in, float *out, int m) {
  
      float temp;
      int i,j;
  
  
      for (i = 0; i &lt; (n - m + 1); i++) {
          temp = 0;
          for (j = i; j &lt; i + m; j++) {
              temp += *(in + j);
          }
          *(out + i) = temp/m;
  
      }
  }
  </code></pre>
  
  <p>Thank you in advance. </p>