title: Step-wise output of Longest Common Sub-sequence program makes no sense to me
body: <p>I am new to dynamic programming and coded a program to find longest common subsequence using dynamic programming however to understand DP better I thought it would be a good idea to print results in each if-else condition in my recursive function, however that output is making no sense to me.</p>
  
  <p>For instance, the first output is "Now m and n both are 0", but why? Shouldn't it be "Last characters B and B are equal " ? I'm sure compiler is using some logic which I'm not aware of, but I really want to know what is actually happening!</p>
  
  <p><a href="https://i.stack.imgur.com/jYObc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jYObc.png" alt="Output"></a></p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstring&gt;
  using namespace std;
  
  int max(int a, int b)
  {
      return (a &gt; b) ? a : b;
  }
  
  int lcs(char *X, char *Y, int m, int n)
  {
      if (m == 0 || n == 0)
      {
          cout &lt;&lt; " Now m and n both are 0" &lt;&lt; endl;
          return 0;
      }
  
      if (X[m - 1] == Y[n - 1])// last character same
      {
          cout &lt;&lt; " Last characters " &lt;&lt; X[m - 1] &lt;&lt; " &amp; " &lt;&lt; Y[n - 1] &lt;&lt; "are equal " &lt;&lt; endl;
          return (1 + lcs(X, Y, m - 1, n - 1)); // add 1 + computer for rest
      }
      else
      {
          cout &lt;&lt; " Last characters " &lt;&lt; X[m - 1] &lt;&lt; " &amp; " &lt;&lt; Y[n - 1] &lt;&lt; "are unequal " &lt;&lt; endl;
          return max(lcs(X, Y, m, n - 1), lcs(X, Y, m - 1, n));
      }
  }
  
  
  int main()
  {
      char X[] = "AGGTAB";
      char Y[] = "GXTXAYB";
      int m = sizeof(X)-1;
      int n = sizeof(Y)-1;
  
      cout &lt;&lt; " LCS length is " &lt;&lt; lcs(X, Y, m, n) &lt;&lt; endl;
  
      int a;
      cin &gt;&gt; a;
  }
  </code></pre>