ProgrammingVery hard

A doubly linked list deletes its head by setting new head = head->next and then new head->prev = NULL. What happens if the list had only one node?

  1. A. The list becomes a circle
  2. B. Nothing, because a single node needs no change
  3. C. The node is freed automatically
  4. D. head->next is NULL, so the second statement must be guarded or it dereferences NULL

Correct answer: D. head->next is NULL, so the second statement must be guarded or it dereferences NULL

With a single node head->next is NULL, and dereferencing it is undefined. A guard is needed.

More C Programming questions

Exams that ask this topic