memory allocation for functions! :(

But what if I use a function that returns pointer of string???
for example...

char* return_name(char *name)
{

name=(char *)malloc(20);

return name;
----------
----------------
-----------------
free(name); /*remving the memory but after the statement "return" this line will not be executed...so the pointer remains mortal and creates bugs when i recall the function */
}

what is to be done in that case???

next is:

char* return_name(char *name)

Does the function allocates memory for the pointer that it returns???
if "yes" then how??? we haven't allocated it and since we haven't done that there is no question about how to free the allocation. so it is containing bugs and creating problems in my programmes.

return name;
----------
----------------
-----------------
free(name); /*remving the memory but after the statement "return" this line will not be executed...so the pointer remains mortal and creates bugs when i recall the function */
}

Is that because you haven't saved the pointer?
how about....

char* return_name(char *name)
{

name=(char *)malloc(20);

return name;
}

then when you call it....

char* name=return_name(input_string);
.
.
.
.
free(name);

For your second question the compiler makes a temporary object to pass the value back to the callee. This is all done behind the scenes and you do not need to worry about it just be aware of whats happening.Just make sure that the value passed back isn't a pointer to a local object within the function.