it frees the memory that text used of course. But how will a system know how much to free or how big the used space is? I think that the system will need to reserve extra space in memory to save how big the dynamic memory array is. Or am I wrong? If so, why does C++ not have any way to retrieve the size?
Your above code is nonsense, but to answer your question:
When malloc returns a pointer P to you, the memory manager (malloc) stores some
information about the size of the block just allocated in the bytes immediately prior
to P in memory. When you free( P ), free looks at those bytes to figure out the
length of the block.
Note: new uses malloc in all implementations I'm aware of and therefore works similarly.
I'd like to point out that even then that code is incorrect. Deleting a pointer to a read-only array such as a string literal will practically always crash the program.
What jsmith and helios want to say about your example is that the memory reserved for text is not dynamically allocated, so not only there is no need to use delete[]/delete on it but doing so can actually cause problems. Only use delete/delete[]/free on memory you reserve with new/new[]/malloc respectively.