Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume the following declarations (which are used to process singly-linked lists

ID: 3643656 • Letter: A

Question

Assume the following declarations (which are used to process singly-linked lists as described in this section):
class Node
{
public:
int data;
Node * next;
};
Node *p1, *p2, *p3;
Assume also that the following statements have been executed:
p1 = new(nothrow) Node;
p2 = new(nothrow) Node;
p3 = new(nothrow) Node;

Tell what will be displayed by each of the following code segments or explain why an error occurs.

Question # 3.
p1 -> data = 123;
p2 -> data = 456;
p1 -> next= p2;
p2 -> next= 0;
cout << p1 -> data << " " << p1 ->next->data << endl;

Question # 4.
p1 -> data = 123;
p2 -> data = 456;
p1 -> next= p2;
p2 -> next= 0;
cout << p2 -> data << " " << p2 ->next->data << endl;

Explanation / Answer

For the Question # 3, the p1 data is displayed but for the address, we need to write only cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote