Possible Duplicate:
C++: How do I decide if to pass params by ref or by value?
The following function has been written from C++ Primer, 5th Edition Page 211 and Page 214. This function will return the position of the first occurrence of a given character in a string and tell the number of occurrences of that character in that string.
string::size_type find_char(const string &s, char c, string::size_type &occurs)
{
// Compares the given character with string
// Records the first occurrence of that character
// The change in &occurs is reflected back to the original variable
}
The authors recommend the use of 'References to Avoid Copies' when passing parameters and the use of 'const
reference parameters' for parameters that the function doesn't change. Why didn't they make char c
a const
reference parameter?