title: Passing arrays, pointers to int in C
body: <p>I'm new to C for numerical analysis after many years of working with Matlab.  I have a function that constructs an array and I need to get it back to main().  I had the usual trouble with arrays vs. pointers, and by fiddling figured out how to do this.  But the fiddling left me with a conceptual question based on the following code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void array_set(int y_out[2][2]);
  void int_set_wrong(int  y);
  void int_set_right(int *y);
  
  
  int main (int argc, const char * argv[]) {
  
      int y_array[2][2]={{0,0},{0,0}};
      int y_int_1 = 0;
      int y_int_2 = 0;
  
      array_set(y_array);
      int_set_wrong(  y_int_1 );
      int_set_right( &amp;y_int_2 );
  
      printf("\nValue array: %d \n",y_array[0][0]);
      printf("Value int wrong: %d \n",y_int_1);
      printf("Value int right: %d \n",y_int_2);
  
      return 0;
  }
  
  void array_set(int y_out[2][2]){
  
      y_out[0][0] = 10;
      y_out[1][0] = 20;
      y_out[0][1] = 1;
      y_out[1][1] = 2;
  }
  
  void int_set_wrong(int y){
  
      y = 10;
  
  }
  
  void int_set_right(int * y){
  
      *y = 10;
  
  }
  </code></pre>
  
  <p>The snippet above returns:
  Value array: 10
  Value int wrong: 0
  Value int right: 10</p>
  
  <p>My question is in a few parts,</p>
  
  <p>first, why does the function 'array_set' work?  I would expect it to fail in the same way that 'int_set_wrong' did.</p>
  
  <p>How are ints and int arrays treated differently in passing?</p>
  
  <p>Furthermore, in the case of 'int_set_wrong', is there a local version of y?</p>
  
  <p>If so, why is there not a local version of y_out in case of setting the array?</p>
  
  <p>Thanks for the help.  As an aside, if there is anything that will cause problems with my implementation of array_set, please chime in.</p>
  
  <p>--Andrew</p>