How to return a string literal from a function
- by skydoor
Hi I am always confused about return a string literal or a string from a function. I was told that there might be memory leak because you don't know when the memory will be deleted?
For example, in the code below, how to implement foo() so that make the output of the code is "Hello World"?
void foo ( ) // you can add parameters here.
{
}
int main ()
{
char *c;
foo ( );
printf ("%s",c);
return 0;
}
Also if the return type of foo() is not void, but you can return char*, what should it be.