pointers ? void printString(string *s){
cout<<*s;
}
int main(){
string name="Honey Bansal";
printString(&name);
return 0;
}
You would want to free the memory as well and if you are using c++ you don't really need to use pointers for strings. Please correct me if I am wrong
But using pointers , we can avoid making copies of string .
You are using a point to a pointer to a string there
Only some types are copied
That's the C style way for preventing unnecessary copies. Use T const& in C++: void f(std::string const& str) { // do something with `str` }
Обсуждают сегодня