I'm trying to understand this C code for modifying queues:
/*
* create or delete a queue
* PARAMETERS: QUEUE **qptr - space for, or pointer to, queue
* int flag - 1 for create, 0 for delete
* int size - max elements in queue
*/
void qManage(QUEUE **qptr, int flag, int size){
if(flag){
/* allocate a new queue */
*qptr = malloc(sizeof(QUEUE));
(*qptr)->head = (*qptr)->count = 0;
(*qptr)->que = malloc(size * sizeof(int));
(*qptr)->size = size;
}
else{
// delete the current queue
(void) free((*qptr)->que);
(void) free(*qptr);
}
}
What is the **qptr
parameter? What does (*qptr)->head
mean? I know that -> is a pointer to a structure member reference, but I'm lost on what's going on here. I appreciate any tips or advice.