title: Getting reference of the front element when queue is popped
body: <p>I'm playing with some examples to decide whether it is safe to use the reference to the front of the queue when I know it is going to be popped later.</p>
  <pre><code>queue&lt;int&gt; q;
  q.push(5);
  q.push(2);
  int &amp; a = q.front(); // a = 5 now
  q.pop();
  q.push(123);
  cout &lt;&lt; a &lt;&lt; &quot;\n&quot;; // a = 5 now
  </code></pre>
  <p>This example makes it look like it is safe.</p>
  <pre><code>queue&lt;int&gt; q;
  q.push(5);
  int &amp; a = q.front(); // a = 5 now
  q.pop();
  q.push(123);
  cout &lt;&lt; a &lt;&lt; &quot;\n&quot;; // a = 123 now
  </code></pre>
  <p>This example makes me realize I probably have to make a copy of the front element instead of using a reference. However, I do not understand the behavior discrepancy between the two examples. Shouldn't the second example variable &quot;a&quot; also be 5? Can someone explain it to me?</p>