title: Reference pointing to a Null-object
body: <p>I saw this discussion - <a href="https://stackoverflow.com/questions/2099882/checking-for-a-null-object-in-c">Checking for a null object in C++</a> and I was surprised that no one talked about when reference can point to a null object. In our code, we use null objects routinely. There are functions as follows which return nullObj. </p>
  
  <pre><code>const Obj&amp;  
  nullObj()  
  {  
     static obj* nullPtr = NULL;   
     return static_cast&lt;  const Obj&amp;&gt;(*nullPtr);    
  }  
  </code></pre>
  
  <p>Actually, when I looked at the code again to bring this topic up, I had some questions on how the above code works:</p>
  
  <ol>
  <li><p>How is it possible to do <code>*nullPtr</code> - Is is it because nullPtr is a static object, which is allocated memory on the heap and hence it is guaranteed to have some space and</p></li>
  <li><p>Since we are returning const reference to obj, does compiler create a temporary object (to some kind of nullObj??) or Will the const reference act as an alias to nullPtr itself? </p></li>
  </ol>