As an example here, I am creating a 2d array of doubles of 1000 by 2 and filling out every spot in the 2d array with 222222.0
What's really weird is that if I go for example to array[999][1000]
, I get 222222.0
But if I make my array size say only 100 by 2, this doesn't happen and if I try array[99][10]
, I just get 0.0
What's going on? Why do I get this "leakage"?
int N = 1000;
int dimension = 2;
double** nums = malloc(sizeof(double*) * N);
for(int i = 0; i < N; i++)
nums[i] = malloc(sizeof(double) * dimension);
for (int k = 0; k < dimension; k++)
for (int i = 0; i < N; i++)
nums[i][k] = 222222;
printf("%f\n", nums[99][1000]);
222222.000000
Huh?