title: C++ passing string references into functions
body: <p>I have two questions about C++ strings:</p>
  
  <ol>
  <li>The expression <code>string func(string &amp; s)</code> works in a similar fashion to <code>string &amp; func(string &amp; s)</code>, but how do you determine if the return value is referential or non-referential?</li>
  <li>Why can't I use <code>func((string)str)</code> instead?</li>
  </ol>
  
  <p><br/></p>
  
  <p>The code is as follows, including comments showing my intent with questions 1 and 2:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  //Q1:string func(string &amp; s){
  string &amp; func(string &amp; s){
      s[2]='S';
      return s;
  }
  
  int main(){
      char str[]={'H','H','H','H'};
      string name="HHHHH";
      //Q2:string tmp=(string)str;
      //string rest=func(tmp);
      string rest=func((string)str);
      cout&lt;&lt;"rest"&lt;&lt;rest;
  }
  </code></pre>