"Virtual_X" <C.BsM....@gmail.com> wrote in message
news:1184269241.170468.146140@w3g2000hsg.googlegroups.com...
int x=5;
delete(&x);
is the code above delete the block of memory which have be reserved to
x
or the function delete is only for use with pointers
That is in error and most likely when run will produce some type of OS error
such as a segmentation fault.
delete should only be used on memory allocated with new, use delete[] with
new[]
new returns a pointer to the memory, and delete is called on a pointer. How
you get access to that pointer is up to you.
For example, the following program runs on my computer (although I'm not
suggesting you code like this, I'm just saying it's possible).
int main()
{
int* Foo = new int;
int& Bar = *Foo;
Bar = 10;
delete &Bar;
}
Although I didn't delete using the original pointer variable Foo, I did
delete using the value of the pointer itself (I.E, the pointer value that
new returned).