title: printf vs putchar - different output
body: <p>I have this simple code (trying to do an exercise in KandR):-</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
   int c = EOF;
  
   while(c=(getchar() != EOF)){
     printf("%d",c);
   }
  
  return 0;
  }
  </code></pre>
  
  <p>When i run this and enter any character (a single character), i get the output as 11. If i enter multiple characters for example 'bbb' i get the output as 1111. I understand that i have explicitly added brackets to give precendence to the condition check of getchar() != EOF which should either result in 1 or 0. But i don't understand why am i getting multiple 1's.</p>
  
  <p>Another case is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
   int c = EOF;
  
   while(c=(getchar() != EOF)){
     putchar(c);
   }
  
  return 0;
  }
  </code></pre>
  
  <p>No matter which character i enter, i always get the output as a square box with 1's and 0's in it (shown at the bottom of the screenshot below)</p>
  
  <p><img src="https://i.stack.imgur.com/Dn3kj.png" alt="enter image description here"></p>
  
  <p>1) In the first case, why is the output printing more than 1 1's?</p>
  
  <p>2) Why isn't the output of case 2 same as case 1?</p>