0 votes 0 votes Assume that p & q are pointers. What will be the output after performing following sets of operations on a given linked list? Struct node { char info; struct node *link; }; Operations are: q = p → link → link ; q → link → link = p → link; printf (“%c”, q → link → link → link → info); the given ans is b but I am getting c.. can anyone plz verify? anjali007 asked Dec 9, 2018 anjali007 849 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Jaideep Bankoti commented Dec 9, 2018 reply Follow Share answer is b, because in the second operation the second last node (d) is made to point to the head and then in the last operation the element to print is (c->d->a->b). 0 votes 0 votes anjali007 commented Dec 9, 2018 reply Follow Share I think that the second last node points to the second node i.e b because it says p->link which means b .. @Jaideep Bankoti can u plz elaborate 0 votes 0 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes q = p → link → link means q is pointing to node $b$ q → link → link = p → link means node $c$ is now pointing to node $a$ q → link → link → link → info | b | link | → | c | link | →| a | info | → $b$ $so$ $answer$ $ is $ $b$ prashant281188 answered Dec 9, 2018 • selected Dec 9, 2018 by anjali007 prashant281188 comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments Jaideep Bankoti commented Dec 9, 2018 i edited by Jaideep Bankoti Dec 9, 2018 reply Follow Share Thanks @kumar.dilip for notifying my blunder(but node with data item e will detach)! and we all are wrong except @ anjali007. The answer is indeed 'c'. The illustration and the simple code snippet will clarify the doubts. *note that you can change the printf statement and modify output (also the list will loop a,b,c,d,b,c...).☻ https://onlinegdb.com/SkWDGZskE 1 votes 1 votes anjali007 commented Dec 9, 2018 reply Follow Share thanks @Jaideep Bankoti 0 votes 0 votes kumar.dilip commented Dec 9, 2018 reply Follow Share Jaideep Bankoti i don't think so node e will be disconnected. q = p → link → link ; ( q points to node c ) q → link → link ( it will node e because already q is pointing to node c q-> link point to node d and q -> link the it will point to node e) = p → link ( here node b ) then e pointing to node b. q → link → link → link → info q → link( node d) → link (node e)→ link ( node b) → info (node b data) The answer will be b. 0 votes 0 votes Please log in or register to add a comment.