Implementation of dynamic_cast 
<p>The following code produces this output:</p>

<pre><code>1 is a null pointer
2 is not a null pointer
</code></pre>

<p><strong>Code</strong></p>

<pre><code>class base {};
class derived1: public base {};
class derived2: public base {};

int main() {
    base *baseptr[1];
    baseptr[0] = new derived2;
    derived1 *derptr = new derived1;
    derived1 *derivedptr1 = dynamic_cast&lt;derived1*&gt;(baseptr[0]);
    derived1 *derivedptr2 = dynamic_cast&lt;derived1*&gt;(derptr);
    cout&lt;&lt;((derivedptr1==0)?"1 is null pointer":"1 is not a null pointer") &lt;&lt; endl;
    cout&lt;&lt;((derivedptr2==0)?"2 is null pointer":"2 is not a null pointer") &lt;&lt; endl;
}
</code></pre>

<p>Why is derivedptr2 only initialised and derivedptr1 is not? As both have a valid right hand side value. Does this have something to do with dynamic cast and the fact that in second case I am casting a derived1* to a derived1*?</p>
