Is it preferred to pass a string by reference in C++?
For null terminated string char* or char[], it is already a pointer. Passing by reference only means to pass a pointer. All arrays are always passed by reference, never by value.
STL string1. STL string is NOT a primitive data type; it is a class and thus cannot be handled like the traditional pointer to variable.
2. We can pass strings by reference (string& myString, or const string& myString) or by value (string myString).
3. const string& myString mimics the protection of a variable that passing by value but saves copying overhead. In this case, passing by reference is preferred.