If deleting the pointer, why is the output 5 5?(I'm new)
#include <iostream>
using namespace std;
int main(){
int* i = new int(5);
cout<< *i <<endl;
delete i;
cout<< *i <<endl;
return 0;
}
If deleting the pointer, why is the output 5 5?(I'm new)
#include <iostream>
using namespace std;
int main(){
int* i = new int(5);
cout<< *i <<endl;
delete i;
cout<< *i <<endl;
return 0;
}
Delete doesn't set 0 or any value to the memory i
is pointing to. It just flags it as free so something can use it later. This leads to undefined behaviour