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

MCQ · 1 mark · Problem PROG-DSTR-0123

Consider the C code fragment given below.
typedef struct node {
int data;
node* next ;
} node;
void join (node* m, node* n) {
node* p=n ;
while (p->next ! =NULL){
p = p -> next ;
}
p-> next = m;
}
Assuming that m and n point to valid NULL- terminated linked lists, invocation of join will
  1. A
    append list m to the end of list n for all inputs.
  2. B
    either cause a null pointer dereference or append list m to the end of list n.
  3. C
    cause a null pointer dereference for all inputs.
  4. D
    append list n to the end of list m for all inputs.

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/118711/gate2017-1-8

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