What does the following function do for a given Linked List with the first…

2025

What does the following function do for a given Linked List with the first node as head?

void fun1(struct node* head)
{
    if(head == NULL)
        return;

    fun1(head->next);

    printf("%d ", head->data);
}

  1. A.

    Prints all nodes of linked list

  2. B.

    Prints all nodes of linked list in reverse order

  3. C.

    Prints alternate nodes of linked list

  4. D.

    Prints alternate nodes in reverse order

Attempted by 125 students.

Show answer & explanation

Correct answer: B

This function uses recursion to traverse the linked list. It first calls itself recursively until it reaches the end of the list (when head is NULL). Then, as each recursive call returns, it prints the current node's data. This means nodes are printed in reverse order from head to tail.

Explore the full course: Niacl Ao It Specialist