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?
I assume that char* = string is the same to char* = new char[6]
Share
No. You only need to manually free strings when you manually allocate the memory yourself using the
mallocfunction (in C) or thenewoperator (in C++). If you do not usemallocornew, then thechar*or string will be created on the stack or as a compile-time constant.