I am a little confused by one example in my tutorial. When a string is created, it is created as a type string. However, when the same string is passed to the function, the parameters of the function have a constant, not a string.
Here is the piece of code:
int main()
{
string str;
cout << "blah blah..";
getline(cin, str);
if (is_pal(str))
.
.
.
}
bool is_pal(const string& s)
{
.
.
.
}
why the function parameter const string & s instead of just string & s? I turned the entire tutorial, but I can not find an explanation for this = / Thank you.
source
share