Question: Consider the following code. void f1 (int* ptr2) { int* ptr3; ptr3 } ... H }; int main() { new int [20]; delete []

Consider the following code. void f1 (int* ptr2) { int* ptr3; ptr3 } ... H }; int main() { new int [20];

Consider the following code. void f1 (int* ptr2) { int* ptr3; ptr3 } ... H }; int main() { new int [20]; delete [] ptr3; int* ptr1; f1 (ptr1); return 0; It does not cause memory leak We need to add the following line to the main function: delete ptr1; ptr1 must be declared as a constant pointer for the code to work We need to add the following line to the f1 function: delete ptr2;

Step by Step Solution

3.41 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The image contains a C code snippet with a main function and a function f1 that receives a pointer to an integer The code creates and deallocates dyna... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!