c++ - Deleting a char* crashing program -
this question has answer here:
- deleting *char[] 4 answers
char* str = "hello myname stack"; delete[] str;
why program crashing? char* str allocated on stack?
because it's illegal delete[]
didn't allocate new[]
. that's it.
and no, str
doesn't point something on stack, string literal, immutable , typically resides in read-only segment.
Comments
Post a Comment