title: Printing a variable without assigning a value
body: <p>In C++, what happens if I print a variable that has not been assigned a value? The following two code gives me two different result. Also, the first one gives different result in each compilation and second one prints 0 every time. Why?</p>
  
  <pre><code>int main() {
      int x = 1;
      int y;   // No value has been assigned
      if (x) {
          cout &lt;&lt; y;    // without using endl
          // prints different value each time
      }
  }
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>int main() {
      int x = 1;
      int y;   // y is not initialized
      if (x) {
          cout &lt;&lt; y &lt;&lt; endl;    // using endl
          // prints 0
      }
  }
  </code></pre>