C 2-d array initialization throws segfault : <p>I'm trying to dive a little bit into C programming. So I'm trying to create a 2-d array using double pointers and initializing it with random values. However during the access phase it throws a segmentation fault</p>

<p>Below is a striped down snippet of my code:</p>

<pre><code>int main(void){

// Memory allocation for arrays

int size = 3;

double **matrix = (double **)malloc(sizeof(double *)*size*size);

int i, k;

for(i=0; i&lt;size; i++){
      for(k=0; k&lt;size; k++){
        matrix[i][k]  = ((double)rand())/1314.7;
      }
}

return 0;
}
</code></pre>

<p>Could you please point me what am I doing wrong?</p>
