title: Why does std:endl assign zero to an unitialized variable?
body: <p>Please, consider the following C++ snippet:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main() {
      int x;
      std::cout &lt;&lt; x &lt;&lt; '\n';
      return 0;
  }
  </code></pre>
  
  <p>as expected the result printed will be unpredictable since the variable <code>x</code> has not been initialized. If you run it may get 458785234 and 348934610 the second time. However, if you change the code the following way:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main() {
      int x;
      std::cout &lt;&lt; x &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>Now, the x printed is always equal to zero. Why is that? Note the only change introduced is the <code>std::endl</code>. Can anybody explain why this assigns 0 to <code>x</code> variable?</p>