title: Why can I assign/compare int and char in C
body: <p>I have the code like this : </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  main()
  {
  int c;
  c = getchar();
  while (c != EOF) {
  putchar(c);
  c = getchar();
  }
  }
  </code></pre>
  
  <p>The C documentation says that the <code>getchar()</code> returns the <code>int</code> value. And in the above program we have assigned <code>c</code> type as an <code>int</code>. And most importantly <code>EOF</code> is a <code>integer</code>  constant defined in the header function.</p>
  
  <p>Now if the code changes to something like this:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
      main()
      {
      char c;
      c = getchar();
      while (c != EOF) {
      putchar(c);
      c = getchar();
      }
      }
  </code></pre>
  
  <p>This code also works! Wait a min, as per C documentation <code>getchar()</code> returns<code>int</code>, but see in the above code I'm storing it in <code>char</code>. And C compiler doesn't throw any error. And also in <code>while</code> loop I have compared <code>c</code> which is an <code>char</code> with <code>EOF</code> which is an <code>int</code> and compiler doesn't throw any error and my program executes!</p>
  
  <p>Why does the compiler doesn't throw any error in the above two cases? </p>
  
  <p>Thanks in advance.</p>