title: Why is scanf("%hhu", char*) overwriting other variables when they are local?
body: <p>The title says it all.
  I'm using GCC 4.7.1 (bundled with CodeBlocks) and I faced a strange issue. Consider this:</p>
  
  <pre><code>int main() {
      unsigned char a = 0, b = 0, c = 0;
      scanf("%hhu", &amp;a);
      printf("a = %hhu, b = %hhu, c = %hhu\n", a, b, c);
      scanf("%hhu", &amp;b);
      printf("a = %hhu, b = %hhu, c = %hhu\n", a, b, c);
      scanf("%hhu", &amp;c);
      printf("a = %hhu, b = %hhu, c = %hhu\n", a, b, c);
      return 0;
  }
  </code></pre>
  
  <p>For inputs 1, 2 and 3, this outputs</p>
  
  <pre><code>a = 1, b = 0, c = 0
  a = 0, b = 2, c = 0
  a = 0, b = 0, c = 3
  </code></pre>
  
  <p>If I, however, declare a, b and c as global variables, it works as expected.
  Why is this happenning?</p>
  
  <p>Thank you in advance</p>
  
  <p>Other details:</p>
  
  <p>I'm running Windows 8 64 bits. I also tried with -std=c99 and the problem persists.</p>
  
  <p><strong>Further research</strong></p>
  
  <p>Testing this code</p>
  
  <pre><code>void printArray(unsigned char *a, int n) {
      while(n--)
          printf("%hhu ", *(a++));
      printf("\n");
  }
  
  int main() {
      unsigned char array[8];
      memset(array, 255, 8);
      printArray(array, 8);
      scanf("%hhu", array);
      printArray(array, 8);
      return 0;
  }
  </code></pre>
  
  <p>shows that scanf is interpreting "%hhu" as "%u". It is directly ignoring the "hh". The output of the code with input 1 is:</p>
  
  <pre><code>255 255 255 255 255 255 255 255
  1 0 0 0 255 255 255 255
  </code></pre>