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

Where in the following code segment should a delete statement be put? Explain. (

ID: 3669732 • Letter: W

Question

Where in the following code segment should a delete statement be put? Explain. (C++)

int * p = new int ; // line 1

int * q = new int ; // line 2

* p = 32; // line 3

* q = 20; // line 4

cout << 2 * (* p ) << " " << (* q - 5) << endl ; // line 5

q = p ; // line 6

* p = 10; // line 7

cout << * p << " " << * q << endl ; // line 8

p = new int ; // line 9

* p = 12; // line 10

* q = 62; // line 11

cout * p << " " << * q << endl ; // line 12

Explanation / Answer

int * p = new int ; // line 1

int * q = new int ; // line 2

* p = 32; // line 3

* q = 20; // line 4

cout << 2 * (* p ) << " " << (* q - 5) << endl ; // line 5

q = p ; // line 6

* p = 10; // line 7

cout << * p << " " << * q << endl ; // line 8

delete p;

p = new int ; // line 9

* p = 12; // line 10

* q = 62; // line 11

cout * p << " " << * q << endl ; // line 12

delete p;

delete q;

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