Hi everyone,
I've been working with pointers for quite some time and I'm familiar with all the pointer-reference stuff. One of the things I don't get is the function of the delete keyword.
I have used this code to find out what the delete keyword does.
int main(int argc, char *argv[]) {
int *i;
if (i) cout << i << ": " << *i << endl;
i = new int(6);
if (i) cout << i << ": " << *i << endl;
delete i;
if (i) cout << i << ": " << *i << endl;
i = new int(8);
if (i) cout << i << ": " << *i << endl;
delete i;
system("PAUSE");
return EXIT_SUCCESS;
}
This gave me this output:
[Address1]: -xxxxxxxx
[Address2]: 6
[Address2]: xxxxxxx
[Address2]: 8
So I'm confused with this output. Does the if (i) statement tell me that the pointer has been initialized, or does it always return true? How do I detect whether the address points to a valid location? (As in, no gigantic positive or negative numbers.) Why doesn't the address change when I call delete and call new again?
Help will be much appreciated.