How does this C++ code work? Uninitialized Pointer
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2533476/what-will-happen-when-i-call-a-member-function-on-a-null-object-pointer">What will happen when I call a member function on a NULL object pointer?</a>  </p>
</blockquote>



<pre><code>class A {
  public:
    void foo() { cout &lt;&lt; "Work";}
    void bar() { this-&gt;foo(); }//new edit, works too!
};

class B {
  private:
    A *a; //never initialized
  public:
    A&amp; getA() {
      return *a;
    }
};

void SomeFunction() {
    B *b = new B();
    B&amp; bRef = *b;
    bRef.getA().bar();//edited
    delete b;
}
</code></pre>

<p>I called SomeFunction() without initializing "a" and it still prints "Work" correctly. I don't understand why, it should have bailed out with segmentation fault!</p>
