When a String variable is declared and modified inside a function, where does it go? To the heap(as string declaration is a part of dynamic memory allocation) or to the stack(as it is a part of function)? And is the space regained after the function goes out of the scope? For example
void loop()
{
Serial.println(foo("def"));
while(1);
}
String foo(String arg1)
{
String test = "abc";
test = test + arg1;
return test;
}
So, in this case, the variable "test" is declared in stack or heap? And this space is regained at the end or not?
Modified: What if inside loop variable is declared like below?
String foo_test = F("def");
Serial.println(foo(foo_test));
In this case what will be the scenario?