wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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
cause a null pointer dereference for all inputs.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
either cause a null pointer dereference or append list m to the end of list n.
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
append list m to the end of list n for all inputs.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
append list n to the end of list m for all inputs.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B either cause a null pointer dereference or append list m to the end of list n.
Consider two linked lists:


After the code execution, list 'm' will be appended to the end of list 'n'. But in some cases it can cause all pointer dereferenced also.

flag
Suggest Corrections
thumbs-up
1
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Encoding and Decoding
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon