How can I modify the value of a string being passed as argument in a function?
For example I have this function foo
(that is supposed to change the value of return_string
from "old string"
to "new string"
):
int foo(char *return_string) {
char *tmp = "new string";
return_string = tmp;
return 0;
}
But if I call it in the following way:
char *s = "old string";
foo(s);
printf("%s\n", s);
I still get old string
as output. Why?
I admit I have a little of confusion with pointers and strings in C.