Is this the correct method to define an 5*3 matrix using double pointers?`
 int **M1;
 M1 = (int **)malloc(5 * sizeof(int *));
 for (i=0;i<5;i++)
 {
    M1[i] = (int *)malloc(3 * sizeof(int));
 }`
If so, how can I assign M1[3][15] = 9 in the code and still get no error? And why am I getting a segmentation error in assigning M1[6][3]=2?
I understood after few such initializations that I created a 5*xx array, i.e. I couldn't go above 5th row but I could assign any value to the number of columns. How should I create just a 5*3 array?
 
     
    