140734958778559
140734958778480= nieuwe adres
4454353440
For one, I don't understand why the function is using an address with a lower number than the first declared char c.
More important, I was expecting I was passing tp the address of nieuwe.
Yet it didn't happen and created a whole new address>
cout << (long)&nieuwe << "= new address"<< endl;
You are printing the address of the pointer. Remove the & and you should get the same output as line 15 gives.
Great, now still one more thing I don't understand. I made the function slightly more complex now, pointing to a "array" rather than a single char.
When trying to delete that array afterwards, it appears not to be empty.
Note that sizeof(cp) will give you the size of the pointer and not the size of the string.
You shouldn't access the array after it has been deleted. It's undefined behaviour and anything could happen.
What probably happens is that the memory still contains the same content ready to be used for future allocations. If you allocate a new array it is likely that it will get the same address and the same content as the old array had when it was deleted.
delete[] tp;
cout << (long)tp << "= " << tp[4] << endl;
Why does delete[] tp not delete the array it's pointing to?
delete[] does in fact delete the array it's pointing to, where "deleting" stands for marking the storage the array occupied as available for future allocations, and executing the destructors of the array elements (which, in your case, do nothing)
However it does not modify the value of the object (of type char*) called "tp", so it still holds the same address, and since no new allocations happened yet, when you're accessing the freshly deleted array element with tp[4], you're still seeing the old value. In this case, on your compiler. But be aware that dereferencing a pointer to the non-existant object is undefined behavior and not guaranteed to work (however you define 'work').
You should treat that tp after delete[] tp; the same way you'd treat it after char* tp;, as an invalid pointer.
Also keep in mind that new[]/delete[] are almost never used in C++: we have strings and vectors.