title: Two almost exactly the same programs but different output
body: <p>Hi I have made a very simple program that should work but it don't:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char *argv[]) {
      int usedNumbers[256];
      memset(usedNumbers,0,256);
  
      srand(time(NULL));
  
      for(int i=0; i&lt;256; ++i){
          while(1){
              int r = rand()%256;
              if( !usedNumbers[r] ){
                  usedNumbers[r] = 1;
                  break;
              }
              printf("Test: %03d -&gt; %03d\n", i, r);
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The idea of the program is to print numbers from 0 to 255 on the screen in the random order but the program stops on 84th number on 32 computers and 144th number on 64 bit computers. If i only move the "int usedNumbers[256];" above the function like that:</p>
  
  <pre><code>#include &lt;string.h&gt;
  
  int usedNumbers[256];
  
  int main(int argc, char *argv[]) {
  </code></pre>
  
  <p>Program works as it supposed to.
  Why is it that?
  I am using the newest GNU/GCC compiler and C11 standard.</p>