ProgrammingVery hard
A queue with head and tail pointers is emptied by dequeuing its only node. What must the dequeue do to keep the queue correct?
- A. Set the tail pointer to NULL as well as the head
- B. Leave the tail pointing at the freed node
- C. Set the head to the tail's value only
- D. Free the tail and keep the head unchanged
Correct answer: A. Set the tail pointer to NULL as well as the head
If tail still points at the freed node, the next enqueue writes into freed memory. Both pointers must become NULL when the queue is empty.
More C Programming questions
- A recursive function removes all nodes equal to x from a singly linked list and returns the new head. Which return statement is the right…
- A program creates an array of 10^6 pointers and then one malloc block per pointer, with 10^6 frees at the end. What is the total number of…
- What is the effect of realloc(p, 0) when p came from malloc, in the C standard's terms?
- A function returns a pointer to a dynamically allocated copy of its argument string. Which signature is the most correct for the caller's…
- int m = malloc(3 sizeof m); for (int i = 0; i < 3; i++) m[i] = malloc(4 sizeof m); What is the number of allocation calls made in total?
- A doubly linked list node has prev and next. What must happen before freeing the node p in the middle of the list?