title: Unsigned and Signed int and printf
body: <p>I understand that I am assigning signed int a value that is larger than what it can handle. Also I should be using <code>%d</code> for signed and <code>%u</code> for unsigned. Similarly I should not be assigning <code>-ve</code> value to unsigned. But if I make such assignments and use printf as below, I get the results show below.</p>
  
  <p>My understanding is that in each case, the number of converted to its two's compliment binary representation which is same for <code>-1</code> or <code>4294967295</code>. That is why <code>%u</code> for signed prints <code>4294967295</code> by ignoring <code>-ve</code> leftmost bit. When used %d for signed int, it uses left most bit as <code>-ve</code> flag and prints <code>-1</code>. Similarly <code>%u</code> for unsigned prints unsigned value but <code>%d</code> causes it to treat the number as signed and thus prints <code>-1</code>. Is that correct?</p>
  
  <pre><code>signed int si = 4294967295;
  unsigned int  ui = 4294967295;
  
  printf("si = u=%u d=%d\n", si, si);
  printf("ui = u=%u d=%d\n", ui, ui);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>si = u=4294967295 d=-1
  ui = u=4294967295 d=-1
  </code></pre>
  
  <hr>
  
  <pre><code>signed int si = -1;
  unsigned int  ui = -1;
  
  printf("si = u=%u d=%d\n", si, si);
  printf("ui = u=%u d=%d\n", ui, ui);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>si = u=4294967295 d=-1
  ui = u=4294967295 d=-1
  </code></pre>