title: Implicit type promotion rules
body: <p><em>This post is meant to be used as a FAQ regarding implicit integer promotion in C, particularly implicit promotion caused by the usual arithmetic conversions and/or the integer promotions.</em></p>
  <p>Example 1)<br />
  Why does this give a strange, large integer number and not 255?</p>
  <pre><code>unsigned char x = 0;
  unsigned char y = 1;
  printf(&quot;%u\n&quot;, x - y); 
  </code></pre>
  <p>Example 2)<br />
  Why does this give &quot;-1 is larger than 0&quot;?</p>
  <pre><code>unsigned int a = 1;
  signed int b = -2;
  if(a + b &gt; 0)
    puts(&quot;-1 is larger than 0&quot;);
  </code></pre>
  <p>Example 3)<br />
  Why does changing the type in the above example to <code>short</code> fix the problem?</p>
  <pre><code>unsigned short a = 1;
  signed short b = -2;
  if(a + b &gt; 0)
    puts(&quot;-1 is larger than 0&quot;); // will not print
  </code></pre>
  <p>(These examples were intended for a 32 or 64 bit computer with 16 bit short.)</p>