Context: I'm trying to wrap my head around pointers, we just saw them a couple of weeks ago at school, and, practicing today, did I come across stupidity? problem, it may be very simple for you, but I have little programming experience.
I saw quite a few questions in SO about deleting pointers, but they all seem to be related to deleting a class, not a "simple" pointer (or whatever rule it may be), here I'm trying to run the code:
So my questions are:
- Why won't the first case work? Seems to be the easiest use to use and delete a pointer? The error says that the memory was not allocated, but "cout" returned the address.
- In the second example, the error does not start, but does the cout of the myPointer value still return the memory address?
- Does # 3 really work? It seems to work for me, the pointer no longer stores the address, is this the correct way to delete the pointer?
Sorry for the long question, I wanted to make it as clear as possible, and also repeat, I have little experience in programming, so if someone could answer it using non-professional questions, it would be very useful!
c ++ pointers delete-operator
leopic Nov 04 2018-12-12T00: 00Z
source share