What are the issues with the following function void foobari

What are the issues with the following function? void foobar(){int x=10; int* q=&x; int* p=new int[5]; delete q; delete &x;}

Solution

Given Function is
void foobar()
{

int x=10; //Here we are Initializing the value of x
int* q=&x;Here we are assigning x value to q i.e q=10
int* p=new int[5];//here p value is zero
delete q;// this statement deletes the q value
delete &x;// this statement deletes the &x value
}

The above function causes Run time error because after Initializing x value & assigning &x value to q we are deleting both values so it leads to Runtime error.

 What are the issues with the following function? void foobar(){int x=10; int* q=&x; int* p=new int[5]; delete q; delete &x;}SolutionGiven Function is v

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site