title: unwanted changing value of an array element being address/number of element for the second array in C
body: <p>I have problem that really confuses me a lot. I want to have a sparse matrix stored in 3 arrays and perform matrix/vector multiplication. Matrix and vectorB are red from a file. That's the background. The problem is in unwanted changing the value of an integer array element being an "argument" of the double array. Here is what I am doing:</p>
  
  <pre><code>int row[ELEMENTS_NO] = {0};
  int col[ELEMENTS_NO] = {0};
  double values[ELEMENTS_NO] = {0.0};
  double vectorB[M_SIZE] = {0.0};
  double res[M_SIZE]={0.0};
  
  ...reading row,col,values, from the file...
  
  printf("\n row[0]:%d, col[0]:%d",row[0],col[0]);
  
  for (k = 0; k &lt; ELEMENTS_NO; k++) {
          res[row[k]] = res[row[k]] + values[k]*vectorB[col[k]];
      }
  
  printf("\n\n\n row[0]:%d, col[0]:%d",row[0],col[0]);
  </code></pre>
  
  <p>the output of the first print is correct:</p>
  
  <blockquote>
    <p>row[0]:1, col[0]:1</p>
  </blockquote>
  
  <p>while the second print gives me following output:</p>
  
  <blockquote>
    <p>row[0]:1352932126, col[0]:1</p>
  </blockquote>
  
  <p>Why the value of col array changed after executing for loop? How to solve my problem and remain row and col elements unchanged?</p>
  
  <p>Thank you for any useful information!</p>