I'm trying to create an undefined 2D m x m array as global variable. But after I type the m value, I get a
segmentation fail(core image dumped)
error. Can anyone help me with this? Thank you very much. Here's my code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double **A;
int main(void) {
int m, i, j;
scanf("%d", &m);
A = (double **)malloc(m * m * sizeof(double));
for (i = 0; i < m; i++) {
for (j = 0; j < m; j++) {
A[i][j] = i + j;
}
}
return 0;
}
A[i], which is uninitialized.double *instead ofdouble **. Access via:A[(i * m) + j]instead ofA[i][j]