title: Why does the unsigned int give a negative value in c++?
body: <p>I have two functions add and main as follows.</p>
  
  <pre><code>int add(unsigned int a, unsigned int b)
  {
      return a+b;
  }
  
  int main()
  {   
     unsigned int a,b;
     cout &lt;&lt; "Enter a value for a: ";
     cin &gt;&gt; a;
     cout &lt;&lt; "Enter a value for b: ";
     cin &gt;&gt; b;
     cout &lt;&lt; "a: " &lt;&lt; a &lt;&lt; "   b: "&lt;&lt;b &lt;&lt;endl;
     cout &lt;&lt; "Result is: " &lt;&lt; add(a,b) &lt;&lt;endl;
  
     return 0;
  }
  </code></pre>
  
  <p>When I run this program I get the following results:</p>
  
  <pre><code>Enter a value for a: -1
  Enter a value for b: -2
  a: 4294967295   b: 4294967294
  Result is: -3
  </code></pre>
  
  <p>Why is the result -3?</p>