title: How does C evaluate these programs?
body: <p>While learning C I arrived at a point where I was evaluating numerical expressions.</p>
  
  <pre><code>main()
  {
      printf("%d",4*1/2+3/2*1+2+3.2);
  }
  </code></pre>
  
  <p>Here I expect the expression to evaluate to 8.2 (following the hierarchy of operators) and since it's being printed as an integer the value printed on the screen should be 8 </p>
  
  <p>But what I get is <code>26214</code>.<br>
  Why does this value get printed on the screen? (It's remains the same no matter how many times I run it).  </p>
  
  <hr>
  
  <p>If I however run the following code,</p>
  
  <pre><code>main()
  {
      int a;
      a=4*1/2+3/2*1+2+3.2;
      printf("%d",a);
  }
  </code></pre>
  
  <p>I get the expected value <code>8</code>.<br>
  The only thing that varies between the two cases is I use a int variable in the second case and print that.  </p>
  
  <p>Why does this give me the right answer?</p>
  
  <hr>
  
  <p>Since C is quite prehistoric, I would expect someone might have already asked a similar question. I have searched a bit. If someone could point me to such a question that would be great.  </p>
  
  <hr>
  
  <p>I would appreciate if someone could supply a better title to this question.</p>