vendredi 14 août 2015

Ambiguity in 2d array declaration in C

I have defined array in the following formats, but apparently the program works fine only in CASE B.

CASE A:

int **M1;
M1 = (int **)malloc(m * sizeof(int *));
for (int i=0; i<m; i++){
    M1[i] = (int *)malloc(d * sizeof(int));
} 

CASE B:

int (*M1)[m] = malloc(sizeof(int[m][d]));

I am getting a segmentation error in CASE A. What could be the reason?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire