title: Applying modulo operation on a value of type int and unsigned integer
body: <p>For example the code below</p>
  
  <pre><code>int a = -7777;
  int b = 10;
  cout&lt;&lt; a % b&lt;&lt;endl;
  cout&lt;&lt;(a+b)%b&lt;&lt;endl;
  cout&lt;&lt; -7777%10 &lt;&lt;endl;
  </code></pre>
  
  <p>The results are:</p>
  
  <pre><code>-7
  -7
  -7
  </code></pre>
  
  <p>but if I changed the type of b to unsigned int, it has different values;</p>
  
  <pre><code>int a = -7777;
  unsigned int b = 10;
  cout&lt;&lt; a % b&lt;&lt;endl;
  cout&lt;&lt;(a+b)%b&lt;&lt;endl;
  cout&lt;&lt; -7777%10 &lt;&lt;endl;
  </code></pre>
  
  <p>The resutls are </p>
  
  <pre><code>9
  9
  -7
  </code></pre>
  
  <p>Could any body advise how it is working here? How do the differences come?</p>
  
  <p>Btw: I am using C++ in Xcode latest version. </p>