Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Data Structures | Linked List | Question 17

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Consider the following function to traverse a linked list. 

C




void traverse(struct Node *head)
{
   while (head->next != NULL)
   {
       printf(\"%d  \", head->data);
       head = head->next;
   }
}

Which of the following is FALSE about above function?

(A)

The function may crash when the linked list is empty

(B)

The function doesn\’t print the last node when the linked list is not empty

(C)

The function is implemented incorrectly because it changes head

(D)

None of the above


Answer: (C)

Explanation:

This statement is false because it is common for a function that traverses a linked list to change the head pointer, in order to move through the list. In the given function, the head pointer is initially passed in as a parameter, and then it is updated to point to the next node in the list during each iteration of the while loop. This is a standard approach to traversing a linked list.


Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads
Related Tutorials