when does the memory, pointed by (char *) as function parameter gets deleted?
c++, char, parameter-passing
Solution
You can think of string literals as being part of the code. They aren't dynamically allocated, they have so-called "static storage duration", which means they exist for the duration of the program, and they don't need to be freed (indeed, must not be freed).
It is always wrong to `delete[]` something that wasn't created with `new[]`, so your second code snippet has undefined behavior.
Problem
code 1 : ``` void foo(char * text) {} foo("Test"); ``` as far as i understand, this will happen : memory is allocated for "Test" pointer is created and its value is copyed to (char * text pointer), so (char * text) points to the place in memory, where "Test" is (better to say, on the first char of "Test") after the function is done, it destroys the pointer(char * text), pointing to the beginning of "Test", doesnt create this a memory leak? and the question is, when does the "Test" gets deleted, when the function destroys only the pointer isn't it better to do smth. like that? : ``` char * _text = "Test"; foo(_text); delete[] _text; ```