I am trying to allocate memory for a triple pointer. I have the following:
int i, j;
int n = 4;
int ***X = (int ***) malloc(sizeof(int) * n);
for(i = 0; i < n; i++){
printf("h\n");
X[i] = (int **) malloc(sizeof(int) * n);
for(j = 0; j < n; j++){
printf("j\n");
X[i][j] = (int *) malloc(sizeof(int) * n);
}
}
X[0][0][0] = 14;
X[1][2][2] = 15;
When I run this on Linux, I get *** glibc detected *** triplePointer: double free or corruption (out): 0x0000000000ea3050 ***
error which I have completely no idea what it is implying. But when I run it on Windows with the -Wall flag, I get no errors. Can someone perhaps help me to find where my error is at.
Also, I am currently hard coding by having the statement X[0][0][0] = 14;
. Is there a way that I can populate all the slots of this triple pointer by some random values?