title: what is the difference between volatile and local variable in c?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/949433/could-anyone-explain-these-undefined-behaviors-i-i-i-i-i-etc">Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc&hellip;)</a>  </p>
  </blockquote>
  
  
  
  <p>Code 1: </p>
  
  <pre><code>   main()
    {
     int a=5;
     printf("Value : %d %d %d %d\n",a++,a++,++a,a++);
    }
    ANS:
    Value : 8 7 9 5
  </code></pre>
  
  <p>Code 2: </p>
  
  <pre><code>   main()
    {
     volatile int a=5;
     printf("Value : %d %d %d %d\n",a++,a++,++a,a++);
    }
    ANS:
    Value : 8 7 7 5
  </code></pre>
  
  <p>Code 3:</p>
  
  <pre><code>   main()
    {
     int a;
     scanf("%d",&amp;a);
     printf("Value : %d %d %d %d\n",a++,a++,++a,a++);
    }
    INPUT is 5
    ANS:
    Value : 8 7 7 5
  </code></pre>
  
  <p>How the above programs are getting different outputs ?</p>
  
  <p>I experimented volatile variable , it is used to prevent compiler optimizations.
  So I understood the Code 2. But I want to know that ,how the Code 1 and 3 are working ?</p>