title: Is uninitialized data behavior well specified?
body: <p><sub><strong>Note:</strong> I am using the g++ compiler (which is I hear is pretty good and supposed to be pretty close to the standard).</sub></p>
  
  <hr>
  
  <p>I have the simplest class I could think of:</p>
  
  <pre><code>class BaseClass  {
    public:
      int pub;
  };
  </code></pre>
  
  <p>Then I have three equally simple programs to create <code>BaseClass</code> object(s) and print out the [uninitialized] value of their data.</p>
  
  <hr>
  
  <h3>Case 1</h3>
  
  <pre><code>BaseClass B1;
  cout&lt;&lt;"B1.pub = "&lt;&lt;B1.pub&lt;&lt;endl;
  </code></pre>
  
  <p>This prints out:</p>
  
  <pre><code>B1.pub = 1629556548
  </code></pre>
  
  <p>Which is fine. I actually thought it would get initialized to zero because it is a POD or Plain Old Datatype or something like that, but I guess not? So far so good.</p>
  
  <hr>
  
  <h3>Case 2</h3>
  
  <pre><code>BaseClass B1;
  cout&lt;&lt;"B1.pub = "&lt;&lt;B1.pub&lt;&lt;endl;
  BaseClass B2;
  cout&lt;&lt;"B2.pub = "&lt;&lt;B2.pub&lt;&lt;endl;
  </code></pre>
  
  <p>This prints out:</p>
  
  <pre><code>B1.pub = 1629556548
  B2.pub = 0
  </code></pre>
  
  <p>This is definitely weird.  I created two of the same objects the same exact way.  One got initialized and the other did not.</p>
  
  <hr>
  
  <h3>Case 3</h3>
  
  <pre><code>BaseClass B1;
  cout&lt;&lt;"B1.pub = "&lt;&lt;B1.pub&lt;&lt;endl;
  BaseClass B2;
  cout&lt;&lt;"B2.pub = "&lt;&lt;B2.pub&lt;&lt;endl;
  BaseClass* pB3 = new BaseClass;
  cout&lt;&lt;"B3.pub = "&lt;&lt;pB3-&gt;pub&lt;&lt;endl;
  </code></pre>
  
  <p>This prints out:</p>
  
  <pre><code>B1.pub = 0
  B2.pub = 0
  B3.pub = 0
  </code></pre>
  
  <p>This is the most weird yet.  They all get initialized to zero.  All I did was add two lines of code and it changed the previous behavior.</p>
  
  <hr>
  
  <p>So is this just a case of 'uninitialized data leads to unspecified behavior' or is there something more logical going on 'under the hood'?</p>
  
  <p>I really want to understand the default constructor/destructor behavior because I have a feeling that it will be very important for completely understanding the inheritance stuff..</p>