int main()
{
char* str;
str = "string one";
str = "string two";
str = func();
str = "string four";
return 0;
}
char* func()
{
char* tmp;
tmp = "string three";
return tmp;
}
I know str = "string one";
allocates memory for this string and assigns the address of that memory to str
. by right the same thing should happen when str = "string two";
and str = func();
and str = "string four";
are executed, now I'm wondering how memory is handled in this situation. Does memory allocated to those strings release when new assignment happens or it's a form of memory leak?