A. temp = newNode; does not link newNode to the list
B. Missing malloc for newNode
C. newNode->next should not be NULL
D. Head pointer is not updated when list is empty
Solution
Step 1: Analyze the while loop and insertion
The code moves temp to last node, but then does temp = newNode; which only changes temp pointer.
Step 2: Identify correct linking
To link newNode, temp->next should be assigned newNode, not temp itself.
Final Answer:
temp = newNode; does not link newNode to the list -> Option A
Quick Check:
Link newNode by temp->next = newNode [OK]
Hint: Assign newNode to temp->next, not temp [OK]
Common Mistakes:
Assigning newNode to temp pointer instead of temp->next
Forgetting to set newNode->next to NULL
Not handling empty list case
5. You have a singly linked list with nodes 10 -> 20 -> 30 -> NULL. You want to insert 40 at the end using tail insertion. Which of the following code snippets correctly performs this insertion and updates the list?