we use pointers after allocating its memory size....
for example...
char *name=(char *)malloc(20);//allocationg memory
free(name); //removing the pointer
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.
Pls remember that I am a new commer