title: Update values in array in C
body: <p>Assume 2 tables B and Y. Each containing 3 elements. I want to update array <code>Y</code> with the values of array <code>B</code>, so that eventually <code>B[i]=Y[i]</code>. I have come up with the following code. I would expect it for  <code>i=0</code> to perform the retrieve and update function, so that <code>B[0]=Y[0]</code>, then move on to <code>i=1</code> (retrieve and update, so that <code>B[1]=Y[1]</code>) and finally move on to <code>i=2</code> (retrieve and update, so that <code>B[2]=Y[2]</code>).</p>
  
  <p>Instead, firstly it retrieves all values from <code>B</code> (performs <code>retrieve</code> function 3 times consecutively, ie first <code>b=B[0]</code>, then <code>b=B[1]</code> and last <code>b=B[2]</code>) and since the last value of <code>b</code> is <code>b=B[2]</code>, it passes that value with the function <code>update</code> (which is performed next 3 times consecutively) to all positions in array <code>Y</code>. So it ends up with <code>Y[0]=Y[1]=Y[2]=b=B[2]</code>. Any ideas for the rookie? Thanks!</p>
  
  <pre><code>for (i = 0; i &lt; 3; i++)
      b = retrieve (B, b, i);
      y[i] = update(y, b, i);
  
  float retrieve (float B[], float b, int i)
  {
  for (i = 0; i &lt; 3; i++)
       b = B[i];
       return (b);
  }
  
  float update(float y[], float b, int i)
  {
  for (i = 0; i &lt; 3; i++)
      y[i] = b;
      return (y[i]);
  }
  </code></pre>