I need to build an array of pointers to int, all by dynamic memory allocation. I start with declaring:
int** queue = (int**)malloc(sizeof(int*));
and than (size =1)
queue[*size-1] = (int*)calloc(1,sizeof(int));
I scan an integer:
printf("Enter item value to add\n");
scanf("%d",queue[*size-1]);
printf("Item %d added\n",*(queue[*size-1]));
All these code is in the same function and works fine. but when I try to print something from this queue in another function or to free the memory by:
for(i = 0;i<size;i++)
{
free(queue[i]);
}
free(queue);
the program crashes. I would love for some help. Thanks in advance!