Initial linked list: First -> A -> B -> C -> D -> E -> F -> NULL What is the…

Initial linked list: First -> A -> B -> C -> D -> E -> F -> NULL

What is the output after the following sequence of steps?

Code:

struct Node *P;
(i) P = first->link->link->link->link;
(ii) P->link->link = first;
(iii) first->link->link->link = P->link;
(iv) printf("%C", first->link->link->link->link->data);

Answer: A. ACorrect answer: A Initially: first points to A, and the list is A -> B -> C -> D -> E -> F -> NULL. Step (i): P = first->link->link->link->link, so P points…

  1. A.

    A

  2. B.

    B

  3. C.

    C

  4. D.

    F

Attempted by 147 students.

Show answer & explanation

Correct answer: A

Correct answer: A

  1. Initially: first points to A, and the list is A -> B -> C -> D -> E -> F -> NULL.

  2. Step (i): P = first->link->link->link->link, so P points to E.

  3. Step (ii): P->link is F, so P->link->link = first sets F->link = A.

  4. Step (iii): first->link->link reaches C, and the last ->link on the left-hand side is C->link. Therefore C->link is set to P->link, i.e. F. D and E are bypassed.

Final accessible chain: A -> B -> C -> F -> A -> ...

The printf expression uses four links from first: A -> B (1), B -> C (2), C -> F (3), F -> A (4). Therefore it prints A.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…