Also: Use the above diagram for Question I. The shaded boxes represent pointers.
ID: 3561120 • Letter: A
Question
Also: Use the above diagram for Question I. The shaded boxes represent pointers. I) a) Declare and allocate memory to implement the diagram. That is, write C++ statements that will create what is shown in the diagram b) Where are each of the items in memory? c) Deallocate all memory II) Write a function which doubles the size of a dynamic array of string. The existing array may have data. In this case, be sure to copy the data to the new array. Be sure to state any assumptions you are making in the function. Why are they reasonable assumptions? (Information on pointers and functions can be found in the text and in Memory Layout for C++ Part 2)Explanation / Answer
1)
#include<iostream>
using namespace std;
int main()
{
int ***p;
int **r;
p=new int**[sizeof(int**)];
*p=new int*[sizeof(int*)];
**p=new int[sizeof(int)];
***p=18;
r=new int*[sizeof(int*)];
*r=new int[sizeof(int)];
**r=22;
cout<<"Address of 18: "<<p<<" "<<*p<<" "<<**p<<" ";
cout<<endl<<"Address of 18: "<<p<<" "<<*p<<endl;
delete **p;
delete *p;
delete p;
delete *r;
delete r;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.