title: C++ Function "Automatic" Return Value?
body: <p>How is this working? In writing this function, I forgot to include a <code>return</code> statement:</p>
  
  <pre><code>char *getV(const char *var) {
      char *val = nullptr;
      forward_list&lt;formField&gt;::iterator idx;
  
      formField ffld;
      idx = _fields.begin();
      while (idx != _fields.end()) {
          ffld = *idx;
          if (strcmp(ffld.Name, var) == 0) {
              val = ffld.Val;
              break;
          }
          idx++;
      }
  }
  </code></pre>
  
  <p>Here is <code>formField</code>:</p>
  
  <pre><code>struct formField {
      char    *Name   = nullptr;
      char    *Val    = nullptr;
  };
  </code></pre>
  
  <p>Here's how I'm calling the function:</p>
  
  <pre><code>int main () {
      form fdata;
  
      fdata.add("FirstName", "Alan");
  
      char *fval = fdata.getV("FirstName");
      if (fval != nullptr) cout &lt;&lt; fval;
      else cout &lt;&lt; "not found";
      cout &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>I didn't notice the missing <code>return</code> until later, after testing the function and writing other code which uses it. The function is supposed to return <code>*val</code>...and it does! How?</p>