I found a similar question and solutions for that here - returning a local variable from function in C
But came up with another solution for same issue and would like to ask you to evaluate it, is it correct or not?
int myfunction (char **returnval) {
int isvalue = 0;
char *d;
d = "Lorem";
*returnval = d;
return isvalue;
}
int main(int argc, char **argv) {
int func_return;
char *myvar;
func_return = myfunction(&myvar);
printf("myvar=[%s]\n", myvar);
return 0;
}
Output: myvar=[Lorem]
Is that code correct? The memory used by vars won't be lost because of function scope?
Thank you.