title: Memory allocation to define a matrix structure
body: <p>I'm programming A* code and have a weird 'Segmentation Fault' problem trying to access to a int** matrix.</p>
  
  <p>Here the code of an example of matrix. When i try t plot the first cout i obtained a segmentation fault 11.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main(int argc, char** argv)
  {
      int** matriz;
  
      matriz = (int**) malloc(10 * sizeof(int));
  
      // Defino una matriz de 10x12
      for (int i=0; i&lt;10; i++)
      {
          matriz[i] = (int*) malloc(12 * sizeof(int));
  
          for (int j=0; j &lt; 12; j++)
          {
              if( i == 11 &amp;&amp; j == 5)
                  matriz[i][j] = 13;
              else if( i == 10 &amp;&amp; j == 7)
                  matriz[i][j] = 5;
              else if( i == 3 &amp;&amp; j == 11)
                  matriz[i][j] = 4;
              else
                  matriz[i][j] = 0;
          }
      }
  
      // Imprimo valores de prueba para comprobar que todos son accesible y que no encuentro un 'Segmentation Fault'
      cout &lt;&lt; "Valor en (11, 5) --&gt; " &lt;&lt; matriz[11][5] &lt;&lt; endl;
      cout &lt;&lt; "Valor en (10, 7) --&gt; " &lt;&lt; matriz[10][7] &lt;&lt; endl;
      cout &lt;&lt; "Valor normal 0 en (4, 4) --&gt; " &lt;&lt; matriz[4][4] &lt;&lt; endl;
      cout &lt;&lt; "Valor en (3, 11) --&gt; " &lt;&lt; matriz[3][11] &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Someone could tell what i'm doing wrong. I can't understand why i can plot the value of coordinates for example (4,4) and (3,11) but no those (11, 5) or (10,7) which are nears the boders of the matrix.</p>
  
  <p>Thanks in advance.</p>