Consider the following code snippet in C language that computes the number of…

GATE · 2026 · CS · Set 1 · Computer Science & IT

Consider the following code snippet in C language that computes the number of nodes in a non-empty singly linked list pointed to by the pointer variable head.

struct node{

int elt;

struct node *next;

};

int getListSize (struct node *head)

{

if( E1 ) return 1;

return E2;

}

Which one of the following options gives the correct replacements for the expressions E1 and E2?

  1. A.

    E1: head == NULL

    E2: 1 + getListSize(head)

  2. B.

    E1: head->next == NULL

    E2: 1 + getListSize(head->next)

  3. C.

    E1: head == NULL

    E2: 1 + getListSize(head->next)

  4. D.

    E1: head->next == NULL

    E2: 1 + getListSize(head)

Attempted by 258 students.

Show answer

Correct answer: B

The worked solution is available to enrolled students.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…