Hiii everyone
/// Is this fragment of code fine
int main()
{
char *ptr;
ptr = new char[5];
ptr = new char[10];
delete []ptr;
return 0;
}
/// and if It is should I delete ptr twice
Is this fragment of code fine |
No, it leaks memory.
You should delete the memory the first time before you reallocate it (i.e. before
ptr = new char[10];
)
Last edited on