title: What is the purpose of ungetc (or ungetch from K&R)?
body: <p>Can anyone explain to me the purpose of ungetch?
  This is from K&amp;R chapter 4 where you create a Reverse Polish Calculator. </p>
  
  <p>I've ran the program without the call to ungetch and in my tests it still works the same.</p>
  
  <pre><code> int getch(void) /* get a (possibly pushed back) character */
      {
          if (bufp &gt; 0)
          {
              return buf[--bufp];
          }
          else
          {
              return getchar();
          }
      }
  
      void ungetch(int c) /* push character back on input */
      {
          if (bufp &gt;= BUFSIZE)
          {
              printf("ungetch: too many characters\n");
          }
          else
          {
              buf[bufp++] = c;
          }
  
  }
  </code></pre>
  
  <p>(I've removed the ternary operator in getch to make it clearer.)</p>