Hi,
I was trying to see why does this code works , i found it at another website. It is a function to reverse a string
my question is , why does this code works? because I see that each recursive call to the function assigns just one memory location to the "char *reverse " variable and then when the recursive calls end , the variable "char *recursive" is treated like if it was assigned more than one location.Code:char* reverse_str(char* s) { char* reverse = malloc(1); //char* reverse; int i; if(*s != '\0') reverse = reverse_str(s+1); i = strlen(s) - 1; if (i >= 0) reverse[i] = s[0]; return reverse; }
sorry for my english.