I have an interesting problem after allocating a double-pointer.
int **bucket;
bucket = (int **)malloc(sizeof(int) * 10);
I have created a double-pointer without any problem and I have also created a single pointer.
int *size;
size = (int *)malloc(sizeof(int) * 10);
In the first loop, I allocated each element of bucket
, and, second loop, I am assigning zero to every element of size
.
for (i = 0; i < 10; i++)
*(bucket + i) = (int *)malloc(sizeof(int) * 1);
for (i = 0; i < 10; i++)
size[i] = 0;
When I am doing assign operation to size, It deletes the address of certain elements of the bucket. Here, the screenshots while I am debugging.
In this stage I have not entered the 2nd loop:
This is after I entered the second loop:
What can cause this problem? Any thought?