After you delete[]
the array, there is no more array. Any access through that pointer after that has undefined behaviour.
delete[]
is supposed to call the destructors on the array elements and release the storage used by it. Since char
has no destructor it simply releases the storage. Releasing the storage only means that it is no longer in use.
FWIW, there's one more instance of undefined behaviour in your code. "Hello Ther"
has 11 elements: there's a null ('\0'
) terminator at the end. strcpy
ing that into a buffer only 10 elements big is undefined behaviour. You need a buffer with space for 11 elements: the 10 characters of "Hello Ther" plus the null terminator.
This kind of error, a buffer overflow, is a common source of security vulnerabilities. There were famous exploits of this kind of error since at least the 1980s. It would be wise to avoid such unsafe primitives and to prefer safe modern ones (and by "modern" I mean "from the 1990s"), like std::string
. Because, you know, this is the 21st century.