void func(const char *s){
char *result = new char[strlen(s)];
strcpy(result, "new stuff");
s = result;
}
int main(){
const char *str = "old stuff";
func(str);
std::cout << str << "\n";
return 0;
}
The code above compiles without fuss, but str is not changed (still prints out "old stuff"). Why is this? As far as I know, str should be passed by reference into the function, and I should be able to reassign a const char * to point to something else.