How to safely check for null pointers
<p>(Using visual studio 2010)</p>

<p>I have a simple <code>returnLength()</code> function for a list, defined simply as</p>

<pre><code>int returnLength() 
{
    if (!next) return 1;
    else return 1 + next-&gt;returnLength();
}
</code></pre>

<p>next is a pointer to another node in the list.  When checking the if statement to check if next is valid, Visual Studio is throwing a runtime error citing Access violation.  This error is occurring several calls deep into the recursion tree.</p>

<p>What is the recommended way to check whether a pointer exists?</p>
