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;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.