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?
- A. The list becomes a circle
- B. Nothing, because a single node needs no change
- C. The node is freed automatically
- 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
- printf("%d", (5 & 3) << 2 | 1); What is printed?
- int x = 16; printf("%d", x >> 2 ^ 3); What is printed?
- unsigned v = 12; printf("%u", v & -v); What is printed?
- printf("%u", (0u - 1u) % 10); What is printed with 32-bit unsigned int?
- printf("%d", 10 % 3 2 ^ 1); What is printed?
- printf("%d", (unsigned char)~0x0F); What is printed?