I am playing a bit with memory dynamic allocation, but I am not getting any point. While assigning some memory with the statement new statement, I should be able to use the delete to delete the memory.
But when I try / check that this delete command is not working, because the indicator is pointing to that point, which has not been left blank.
Let's take this original piece in a real sense as the code as an example:
#include & lt; Iostream & gt; using namespace std; Int main () {// I'm making a pointer-to-integer pTest, point it to a new location, // and complete this blank space with a number; Int * pTest; PTest = new int; * (Pt) = 3; Cout & lt; & Lt; * (Pte) & lt; & Lt; Endl; // things are working well so far let's // destroy the dynamically allocated space! Remove ptit; // OK, now I think the data has been pTest cout & lt; & Lt; * (Pte) & lt; & Lt; Endl; // oh ... well, I understood return 0; } Any clues?
Time to know what is undefined behavior is :)
C + In + when you do something illegal / nonsensical / bad / etc. the standard often says that "it leads to undefined behavior." This means that beyond that point, the status of your program is completely non-guaranteed, and there may be anything else.
At the point where you do your last * (pTest) , you get undefined behavior because the pTest is a valid object Does not indicate, and such a director dereferencing is unscheduled. So what you are looking for is completely allowed: undefined output.
Whatever you have done, it is said that "I have ended with this allocation." Once you have said that, you can inspect or take care of that memory (and, in fact, not), it does nothing to understand the concept, try to use it; You have said that you have done!
Your output guides to some extent: Chances are, your OS simply says "Ok, thanks for memory" and that's it. There is no reason why there is no real "reset" memory, or something special, it will be a waste of time, when no one is using it (including its own program).
But remember, this output is completely undefined. Do not try to use items that do not exist. Perhaps a better test would happen:
#include & lt; Iostream & gt; Struct foo {~ foo () {std :: cout & lt; & Lt; "Foo has gone: ("
Comments
Post a Comment