Reputation: 53
Please don't come and say "jUst read the error", it doesn't specify it, that's why Im asking here.
int main()
{
int* p, * q;
int a = 10;
p = new int;
p = &a;
delete p;
}
Upvotes: 1
Views: 142
Reputation: 76
p = new int
In this line, you dynamically allocate the memory that you need to delete
.
p = &a
But in this line, you are not allocating new memory, you are pointing p
at stack memory, and leaking the memory that you previously allocated.
Upvotes: 2