title: Why does strcmp() in a template function return a different value?
body: <p>I am reading again &quot;C++ Primer, 5th edition&quot;. In chapter 16 about templates, there is an example of &quot;template Non-type parameters&quot;:</p>
  <pre><code>template&lt;unsigned N, unsigned M&gt;
  int compare(const char (&amp;p1)[N], const char (&amp;p2)[M])
  {
      return strcmp(p1, p2);
  }
  
  int main()
  {
  
      cout &lt;&lt; compare(&quot;hi&quot;, &quot;mom&quot;) &lt;&lt; endl;
      cout &lt;&lt; strcmp(&quot;hi&quot;, &quot;mom&quot;) &lt;&lt; endl;
  
  
      std::cout &lt;&lt; &quot;\ndone!\n&quot;;
  }
  </code></pre>
  <ul>
  <li><p>As we know, <code>strcmp()</code> compares two character strings and returns <code>0</code> for equality, a positive value if <code>str1</code> is greater than <code>str2</code>, and a negative value if <code>str1</code> is less than <code>str2</code>, and this is what I get inside <code>main()</code> calling <code>strcmp()</code>.</p>
  </li>
  <li><p>The problem is in the book example that calls <code>strcmp()</code> inside the template function, so when I run the program I get:</p>
  </li>
  </ul>
  <p>output:</p>
  <pre><code>-5
  -1
  </code></pre>
  <p>What is the problem in the code? And why are the two giving different values for the same arguments?</p>