I want to pass a cstring to a function and have it overwritten.
#include <stdio.h>
void changeStr(char* str1)
{
str1 = "foo";
}
int main()
{
char* aStr = "abc123";
printf("%s\n", aStr);
changeStr(aStr);
printf("%s\n", aStr);//aStr is still the same :(
return 0;
}
I tried putting a &
in front of the aStr and *
in front of str1 but then the program crashes. Why doesn't this work? Isn't the following the same reasoning as here?