Does using a new then setting to null cause memory leaks?
Ive tried the following code but have no idea if it causes any leak or not
#include <iostream>
using namespace std;
int main()
{
int* x = new int;
int y = 1;
x = &y;
x = nullptr; // has the memory allocated to x gone now?
x =&y; // did i recover what was lost?
delete x;
return 0;
}
// the cout<<*x gives 1 as expected
Aucun commentaire:
Enregistrer un commentaire