#include <iostream>
using namespace std;
int main()
{
int *p = new int[7];
delete p;
return 0;
}
Can i deallocate entire block of memory like this in C++? Thanks in advance.
#include <iostream>
using namespace std;
int main()
{
int *p = new int[7];
delete p;
return 0;
}
Can i deallocate entire block of memory like this in C++? Thanks in advance.
Deallocating array allocated with new[]
without square brackets delete[]
is undefined behavior by standard, that means it may seem to work sometimes or it may conjure demons out of your nose sometimes. There are no compiler extensions that make additional guarantees about it.
Use std::vector
when you need dynamic arrays.