What is wrong with the following code? double *firstPtr = new double; //Line 1double *nextPtr = new double; //Line 2*firstPtr = 62; //Line 3nextPtr = firstPtr; //Line 4delete firstPtr; //Line 5delete nextPtr; //Line 6firstPtr = new double; //Line 7*firstPtr = 28; //Line 8cout << *firstPtr << " " << *nextPtr << endl; //Line 9
What is wrong with the following code?
double *firstPtr = new double; //Line 1
double *nextPtr = new double; //Line 2
*firstPtr = 62; //Line 3
nextPtr = firstPtr; //Line 4
delete firstPtr; //Line 5
delete nextPtr; //Line 6
firstPtr = new double; //Line 7
*firstPtr = 28; //Line 8
cout << *firstPtr << " " << *nextPtr << endl; //Line 9
Trending now
This is a popular solution!
Step by step
Solved in 2 steps