Last Updated :
05 Nov, 2018
Consider the following linked list:
An integer pointer S, and an empty node P.
What will be the output of following Statements:
I – P = S → next → next → next
II – P → next → next → next → next = S → next → next → next → next
III – S → next → next → next = P → next → next
IV – X = S → next → next → next → next → next → next → next → data
What will be the value of X?
(A) 5
(B) 6
(C) 7
(D) segmentation error
Answer: (C)
Explanation: Let\’s consider a pointer P:
I – P = S → next → next → next
P = 1000 → 2000 → 3000 → 4000
P = 4000
II – P → next → next → next → next = S → next → next → next → next
4000 → 5000 → 6000 → 7000 → NULL = 1000 → 2000 → 3000 → 4000 → 5000
In place of Null 5000 will be placed
P → next → next → next → next = 5000
III – S → next → next → next = P → next → next
1000 → 2000 → 3000 → 4000 = 4000 → 5000 → 6000
Now 3000 → 6000
IV – X = S → next → next → next → next → next → next → next → data
1000 → 2000 → 3000 → 6000 → 7000 → 5000 → 6000 → 7000 → data
7000 → data = 7.
So, option (C) is correct.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...