Is there a need to destroy char * = "string" or char * = new char[6]?

c++, memory

Solution

No. You only need to manually free strings when you manually allocate the memory yourself using the `malloc` function (in C) or the `new` operator (in C++). If you do not use `malloc` or `new`, then the `char*` or string will be created on the stack or as a compile-time constant.

Problem

I assume that `char* = "string"` is the same to `char* = new char[6]`. I believe these strings are created on the heap instead of the stack. So do I need to destroy them or free their memory when I'm done using them or do they get destroyed by themselves?

Original source