Here is the code,
It compiles just fine. But if I change the definition of the function foo a little bit like this,Code:void foo(const char* s) { s = "mary"; } int main() { char* s = "john"; foo(s); cout<<s<<endl; return 0; }
Then I got compiler errors like "cannot convert parameter 1 from 'char *' to 'const char *&'". It looks like it is fine convert char* to const char* but it is not fine to convert char* to const char *&. Why? Thanks.Code:void foo(const char* &s) { s = "mary"; }