title: Returning a second value through pointer or reference C++
body: <p>I already searched, and couldn't find anything exactly like this one.  Although there do seem to be similarities.  If a mod or admin thinks this is a duplicate topic, please let me know which one and ask me how I think it might be different before you delete it.</p>
  
  <p>If I'm returning an int value in a function, how do I return a second one indirectly with a pointer or reference parameter?  I have a practice problem I need to do that is asking for this:</p>
  
  <blockquote>
    <p>Write a function that takes two input arguments and provides two
    separate results to the caller, one that is the result of multiplying
    the two arguments, the other the result of adding them. Since you can
    directly return only one value from a function, you'll need the second
    value to be returned through a pointer or reference parameter.</p>
  </blockquote>
  
  <p>And I also need to return a string pointer through a function.</p>
  
  <blockquote>
    <ol>
    <li>Write a function that prompts the user to enter his or her first name and last name, as two separate values. This function should
    return both values to the caller via additional pointer (or reference)
    parameters that are passed to the function. Try doing this first with
    pointers and then with references.</li>
    </ol>
  </blockquote>
  
  <p>I already did this one with a reference to a pointer, but I'm having trouble doing it with pointers.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  string userName(string user_first_name, string user_last_name);
  
  int main()
  {
      string user_first_name;
      string user_last_name;
      cout &lt;&lt; "Program for taking in user's full name\n";
      cout &lt;&lt; userName(user_first_name, user_last_name);
  }
  
  string userName(string user_first_name, string user_last_name)
  {
      cout &lt;&lt; "Please provide your first name: ";
      cin &gt;&gt; user_first_name;
      cout &lt;&lt; "Please provide your last name: ";
      cin &gt;&gt; user_last_name;
      string full_name = user_first_name + " " + user_last_name;
      return full_name;
  }
  </code></pre>
  
  <p>Whenever I try to use those string variables as pointers, I get an error saying I can't convert a string to a string*, or I get an error saying I can't convert a string* to a string**.  </p>
  
  <p>As for the other one, this is the code I have:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int* pointerMath();
  
  int main()
  {
      cout &lt;&lt; "Let's do some math!\n";
      pointerMath();
  }
  
  int* pointerMath()
  {
      int value1;
      int value2;
      cout &lt;&lt; "Provide the first number: ";
      cin &gt;&gt; value1;
      cout &lt;&lt; "Provide the second number: ";
      cin &gt;&gt; value2;
      int *multiplication_result = value1 * value2;
      int *addition_result = value1 + value2;
      cout &lt;&lt; "The numbers added together are: " &lt;&lt; *addition_result &lt;&lt; '\n';
      cout &lt;&lt; "The numbers multiplied by each other are: " &lt;&lt; *multiplication_result &lt;&lt; '\n';
      return multiplication_result;
   }
  </code></pre>
  
  <p>Whenever I run this, it always crashes right after getting both input values, and I get an error code 255.</p>
  
  <p>Edit: </p>
  
  <p>I also have to further modify the string name program, per this question's specification: </p>
  
  <blockquote>
    <ol start="3">
    <li>Modify the program you wrote for exercise 1 so that instead of always prompting the user for a last name, it does so only if the
    caller passes in a NULL pointer for the last name.</li>
    </ol>
  </blockquote>
  
  <p>How do I do this?</p>