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. A — Correct 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…
- A.
A
- B.
B
- C.
C
- D.
F
Attempted by 147 students.
Show answer & explanation
Correct answer: A
Correct 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 to E.
Step (ii): P->link is F, so P->link->link = first sets F->link = A.
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.