• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE | GATE-CS-2017 (Set 1) | Question 30

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

(A)

append list m to the end of list n for all inputs

(B)

either cause a null pointer dereference or append list m to the end of list n

(C)

cause a null pointer dereference for all inputs.

(D)

append list n to the end of list m for all inputs.

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments