bool *dat; //create a bool pointer
dat=new bool; //set bool pointing to a address, i.e pointer-to-bool
dat=true; //give value to the pointed address
++dat; //increase the address of bool. Huh-oh, but where is the
//next address. Even worse, what does that address
//contains? Important data ? maybe
dat=false; //what ever it had now its set to false
delete dat; //now you are deleting a vairable that points to a
//different that what it starts with!
--dat; //Its deleted already, so huh?
"If I delete a pointer, does it delete the data in the current address or
all of it?"
If you delete a pointer that variable no longer exist so every thing it
contains also gets deleted.
delete operator releases (deallocates) a block of memory . The cast-expression argument must be a pointer to a block of memory previously allocated for an object created with the new operator. Using delete on a pointer to an object not allocated with new gives unpredictable results.
The new keyword allocates memory for an object or array of objects of type-name from the free store and returns a suitably typed, nonzero pointer to the object. If unsuccessful, by new returns zero or throws an exception;
The delete operator deallocates a block of memory; which frees memory back to the available pool.