I've heard much about the C++ delete
operator and also have used it a lot so far but I don't know what its real work is exactly.
What I have seen on the web have been the talks on "Deallocating storage space" about it, but it does not make sense well to me for understanding the issue completely.
Please have a look at the snippet of code below.
int main()
{
int* p = new int(6);
cout << *p << endl;
delete p;
}
The pointer p
has its own address, since it's a variable (#1). The pointer p
, too, has an address inside itself because it's a pointer(#2). The object (unnamed), contains the value 6 inside its memory block, and the address of that memory block is the same as the address of #2
. (Because the pointer points to that object using that address.)
Now, what will happen to the addresses #1 and #2 after executing delete;
?
What does the C++ language say about this?
And what can be the effect of various compilers on the case?