title: Why can I assign a new value to a reference, and how can I make a reference refer to something else?
body: <p>I have couple of questions related to usage of references in C++. </p>
  
  <ol>
  <li><p>In the code shown below, how does it work and not give a error at line <code>q = "world";</code>?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
    char *p = "Hello";
    char* &amp;q = p;
    cout &lt;&lt;p &lt;&lt;' '&lt;&lt;q &lt;&lt;"\n";
    q = "World"; //Why is there no error on this line
    cout &lt;&lt;p &lt;&lt;' '&lt;&lt;q &lt;&lt;"\n";
  }
  </code></pre>
  
  <ol>
  <li><p>How can a reference q be reinitialized to something else?</p></li>
  <li><p>Isn't the string literal, <code>p = "Hello"</code>, a constant or in read-only space? So if we do,</p>
  
  <pre><code>q = "World";
  </code></pre>
  
  <p>wouldn't the string at <code>p</code> which is supposed to be constant be changed?</p></li>
  </ol></li>
  <li><p>I have read about C++ reference type variables as they cannot be reinitialized or reassigned, since they are stored 'internally' as constant pointers. So a compiler would give a error.</p>
  
  <p>But how actually a reference variable can be reassigned?</p>
  
  <pre><code>int i;
  
  int &amp;j = i;
  
  int k;
  
  j = k; //This should be fine, but how we reassign to something else to make compiler flag an error?
  </code></pre>
  
  <p>I am trying to get hold of this reference, and in that maybe missed some key things related, so these questions.</p></li>
  </ol>
  
  <p>So any pointers to clear this up, would be useful.</p>