Complete the following code by deal locating the memory int

Complete the following code by deal locating the memory int *ptr1 int *p[tr2; ptr1 = new int; ptr2 = new int[10]; *ptr = 10 What\'s wrong with the following code? Fix it int* ptr = new int; *ptr = 8; int* ptr2 = new int; *ptr2 = -5; ptr = ptr2;

Solution

E) Just add below these line below the above code

delete ptr1;

delete[] ptr1;

F) nothing wrong with the code . If we print the values both the pointers locates same value.

int* ptr = new int;
   *ptr = 8;
   int* ptr2 = new int;
   *ptr2 = -5;
   ptr = ptr2;
   cout <<\"ptr =\" << *ptr << \"\ ptr2 =\"<< *ptr2 << \"\ \";

 Complete the following code by deal locating the memory int *ptr1 int *p[tr2; ptr1 = new int; ptr2 = new int[10]; *ptr = 10 What\'s wrong with the following co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site