title: Basic C++ Recursion program questions
body: <pre><code>//This program finds the GCD of two numbers using a recursive function call via the
  //Euclidean algorithm
  
  #include &lt;iostream&gt;
  #include &lt;cmath&gt;
  using namespace std;
  
  int GCD (int A, int B);
  
  int main()
  {
      int A = 45, B = 55;
  
      cout &lt;&lt; "The GCD is " &lt;&lt; GCD(A,B) &lt;&lt; endl;
      //test
      return 0;
  }
  
  int GCD (int A, int B)
  {
      A = abs(A);
      B = abs(B);
  
  
      if (A &gt; B)
      {
          A = A - B;
          return GCD (A, B); //Recursive function call - works fine
          //GCD (A, B);  -- This function call seems to return an incorrect value
  
      else if (A &lt; B)
      { 
          B = B - A;
          return GCD (A, B);//Recursive function call
          //GCD (A, B); -- This function call seems to return an incorrect value
      }
  
      else if (A = B)
      {
          return A;
      }
  }
  </code></pre>
  
  <p>Here's my question: I've noticed that if I dont use the "return" keyword in my recursive function call, the program returns an incorrect value, but if I step through the function, the values in local correctly update. I know that functions (unless they are of the type void) must return a value. Perhaps this rule applies in recursive function calls as well?</p>
  
  <p>Could someone please elaborate/help me understand?</p>