Two Problems Associated Pointer Types Dangling Pointers Lost Heap Dynamic Variables Briefl Q12466135

Two problems associated with pointer types are dangling pointersand lost heap dynamic variables.

a) Briefly describe each of these problems and explain why it isconsidered a problem.

b) Consider the following code in C++:

int * a;

int * b = new int [3];

a = b;

b[0] = 5; b[1] =6; b[2] = 7;

delete b;

int * c = new int[3];

// Asssume that deleted space for b is allocated to c.

c[0] = 1; c[1] = 2; c[2] = 3;

a[1] = 10 ; a[2] = 11;

What are the values of c[0], c[1], and c[2] after this codeexecutes? Explain.

c) Assume the code in part(b) is part of a subprogram thatterminnates immediately after the last statement (so there is no”delete c” statement). If this subprogram is called 20000 times,what is the effect on available memory in the heap, assuming eachint is four bytes long? Explain you answer.

"We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help"
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.