title: How do I return a Null Pointer in a function C++
body: <p>I am currently working on a bit of code that will search within a vector of type Person (which I have defined in the code and will show if needed). If it finds the person, it returns their name. This is currently working, but if it does not find the person, it is supposed to return a Null pointer. The problem is, I cannot figure out how to make it return a Null pointer! It just keeps either crashing the program every time.</p>
  
  <p>Code:</p>
  
  <pre><code>Person* lookForName(vector&lt;Person*&gt; names, string input)
  {
      string searchName = input;
      string foundName;
      for (int i = 0; i &lt; names.size(); i++) {
          Person* p = names[i];
          if (p-&gt;getName() == input) {
              p-&gt;getName();
              return p; //This works fine. No problems here
              break; 
          } else {
              //Not working Person* p = NULL; &lt;---Here is where the error is happening
              return p;
          }
      }
  }
  </code></pre>