void main()
{
int *pPointer = new int;
*pPointer = 25;
printf("Value of *pPointer: %d\n", *pPointer);
delete pPointer;
}
this would be a proper way to delete pointer objects right?
when I debug this code, pPointer doesn't get "deleted", it just points to this really "random" int:
Yes, pointers will, just like normal variables, take up space. You can't delete them in C++, but the variables will be deleted at the end of the scope anyway.
ah, I see . Thanks. What if you had static pointers? wouldn't that cause issues?
and what's with the random int value displaying in my debugger anyway? I deleted my pointer to an new int object, how come it showed -17891602 int as the value?
Hi, I've been reading through those two links and I can't really see an answer to my question :S
I asked: ah, I see . Thanks. What if you had static pointers? wouldn't that cause issues?
Something static will "stay around" until the program exits right? So, if you had too many static pointers, this could be a problem? Even if you're deleting the objects that were created?
And if you delete the object that a pointer was pointing to, is the pointer now known as an "invalid pointer"?