GATE CS 2017 (Forenoon) — Question 8

Data StructuresLinked Lists & Binary TreesMCQ1 mark · −1/3 if wrongMedium

Consider the C code fragment given below.
c
1typedef struct node {
2    int data;
3    node* next;
4} node;
5void join (node* m, node* n) {
6    node* p = n;
7    while (p -> next != NULL) {
8        p = p -> next;
9    }
10    p -> next = m;
11}
12
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.
Practise the full 2017-FN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Linked Lists & Binary TreesTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group