GATE CS 2026 · Set-1 · Arrays & Matrix Representation

MCQ · 2 marks · Problem PROG-DSTR-0082

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 \(\textbf{E1}\) and \(\textbf{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)

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionOfficial GATE Answer Key: Option B.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/523051/gate-cse-2026-set-1-question-29

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com