New & Delete Operators
In the Visual Studio Code editor, I tried to use the new
and delete
operators, but the editor throws an error which I am unable to figure out. I tried out everything to remove the error, but all in vain!!!
#include <iostream>
using namespace std;
int main()
{
int avg, *ptr1, *ptr2, *ptr3;
ptr1 = new int;
ptr2 = new int;
ptr3 = new int;
cout << "Enter the first number : ";
cin >> *ptr1;
cout << "Enter the second number : ";
cin >> *ptr2;
cout << "Enter the third number : ";
cin >> *ptr3;
avg = (*ptr1+*ptr2+*ptr3)/3;
cout << "Average is : " << avg << endl;
delete ptr1;
delete ptr2;
delete ptr3;
return 0;
}
This is the Error that is displayed: