Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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. append list m to the end of list n for all inputs.
    2. either cause a null pointer dereference or append list m to the end of list n.
    3. cause a null pointer dereference for all inputs.
    4. append list n to the end of list m for all inputs.
Correct Option: B

According to the given C program. It used two linked lists. After the code execution, list ‘m’ will be appended to the end of list ‘n’ due to pointer ‘p’. Move to last node of the list but in some cases it may dereference to null pointer.



Your comments will be displayed only after manual approval.