title: Difference between %u and %d in scanf()
body: <p>In C++, if I read an integer from a string, it seems it does not really matter whether I use <code>u</code> or <code>d</code> as conversion specifier as both accept even negative integers.</p>
  
  <pre><code>#include &lt;cstdio&gt;
  using namespace std;
  
  int main() {
      int u, d;
      sscanf("-2", "%u", &amp;u);
      sscanf("-2", "%d", &amp;d);
      puts(u == d ? "u == d" : "u != d");
      printf("u: %u %d\n", u, u);
      printf("d: %u %d\n", d, d);
      return 0;
  }
  </code></pre>
  
  <p><sup><a href="http://ideone.com/tBQp7G" rel="noreferrer">Ideone.com</a></sup></p>
  
  <p>I dug deeper to find if there is any difference. I found that</p>
  
  <pre><code>int u, d;
  sscanf("-2", "%u", &amp;u);
  sscanf("-2", "%d", &amp;d);
  </code></pre>
  
  <p>is equivalent to</p>
  
  <pre><code>int u, d;
  u = strtoul("-2", NULL, 10);
  d = strtol("-2", NULL, 10);
  </code></pre>
  
  <p>according to <a href="http://en.cppreference.com/w/cpp/io/c/fscanf" rel="noreferrer">cppreference.com</a>.</p>
  
  <p><strong>Is there any difference at all between <code>u</code> and <code>d</code> when using these conversion specifiers for parsing, i.e. in format passed to <code>scanf</code>-type functions? What is it?</strong></p>
  
  <p><sub>The answer is the same for C and C++, right? If not, I am interested in both.</sub></p>