title: Finding 2D array cell memory location
body: <p>There is an array <strong>a[3][4]</strong> and we have to find the address of <strong>a[2][2]</strong> using <strong>row major order</strong> and <strong>1001 as base address</strong>. I found 2 formulas do find the address:</p>
  
  <pre><code>For any array a[M][N] Row Major Order:
  
  1) a[i][j] = Base Address+Datatype Size[(N*i)+j]
  
  2) a[i][j] = Base Address+Datatype Size[N*(i-1)+(j-1)]
  </code></pre>
  
  <p>I tried both the formulas but the first one yielded the correct result but not the second one. Here is how I found the address of a[2][2] using row major order:</p>
  
  <pre><code>Using Formula 1:
  
  a[2][2] = 1001+2[(4*2)+2]
          = 1001+2[10]
          = 1001+20
          = 1021 (correct answer)
  
  Using Formula 2:
  
  a[2][2] = 1001+2[4*(2-1)+(2-1)]
          = 1001+2[4+1]
          = 1001+2[5]
          = 1001+10
          = 1011 (Wrong Answer)
  </code></pre>
  
  <p>Is there any error in my 2nd formula or have I done something wrong in the calculation using 2nd formula? Why aren't both the answers coming same?</p>