I want to return a C style string from a function. I found this solution: Solution
const char* myName() {
char *name = "Flavio";
return name;
}
However I don't understand how this works. How come the c string isn't destroyed when it goes out of scope? How does the heap work in this case? Do consecutive calls to the function allocate more and more memory on the heap; causing a memory leak? How is the string cleared off the heap?
Thanks.