title: Modifying array inside a function in C
body: <pre><code>// test.txt
  50
  13
  124
  </code></pre>
  
  <p>-</p>
  
  <pre><code>void hi ( int *b, FILE *pfile ) {
  
      rewind ( pfile );
      int i;
      for( i = 0 ; i &lt; 3 ; i++ ) {
           fscanf ( pfile, "%d", &amp;b[i] );
      }
  }
  
  int main ( void ) {
  
      FILE *fp = fopen ( "test.txt", "r" );
      int a[10];  //putting extra size for test.
  
      hi ( &amp;a[0], fp );   
      printf("%d,%d,%d\n", a[0], a[1], a[2]);
  
      fclose ( fp );
      return 0;
  }
  </code></pre>
  
  <p>I'm trying to understand pointers when there's array involved. While I was testing the code above, I noticed that by putting a different index value such as <code>hi ( &amp;a[0], fp )</code> to <code>hi ( &amp;a[1], fp )</code> I get different results. </p>
  
  <p><code>//result of [ hi ( &amp;a[0], fp ) ]              //result of [ hi ( &amp;a[1], fp ) ]
     50,13,124                                     junk#,50,13                 .</code></p>
  
  <p>I am really confused about the results because in the 'hi' function I specify the start of the array from <code>i = 0</code> which should mean it's storing the value starting from <code>a[0]</code>. But it seems like putting <code>1</code> instead of <code>0</code> is somehow moving values aside. Why is this happening?</p>