title: C++ assigning value to multidimensional array
body: <p>I am trying to assign values to each index in my 3x3 dimensional array. I initialized all the values to be 1 at the beginning, then set index[0][2] to be 2. however, somehow index[1][0] also attached to the value 2. then i tried to set [1][2] to 2, and [2][0] also set to value 2. I am not sure what is happening here?</p>
  
  <h2> 1 |  2 |  1 | ----> 1 |  1 |  2 |</h2>
  
  <h2>1 |  1 |  1 |  ---->  1 |  1 |  1 |</h2>
  
  <h2> 2 |  1 |  1 |  ---->        1 |  2 |  1 |</h2>
  
  <pre><code>void magicSquare (int param){
  //param = 3
  int volume = param - 1;
  
  int squareArray[volume][volume];
  
  int c = 0;
  int d = 0;
  
  for (int i = 0; i &lt; param*param; i++) {
  
      squareArray[c][d] = 1;
      c +=1;
       if (c == param) {
                  d +=1;
                  c = 0;
  
       }
  
  }
  
  squareArray[0][2]= 2;
  
  
  c = 0;
  d = 0;
  
  printf (" %d | ",squareArray[c][d]);
  for (int i = 1; i &lt; param*param; i++) {
  
      c +=1;
  
      if (c == param) {
          d +=1;
          c = 0;
          printf ("\n %d | ",squareArray[c][d]);
      }
      else printf (" %d | ",squareArray[c][d]);
  
  }
  </code></pre>