title: How is the C code functioning?
body: <p><strong>Introduction:</strong> I'm following 'The C Programming Language' by K&amp;R and I came across a section of the following code that I'm unable to comprehend.</p>
  
  <p><strong>The Code:</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      int c, i, nwhite, nother;
  
      int ndigit[10];
  
      nwhite = nother = 0;
      for (i = 0; i &lt; 10; i++)
      {
          ndigit[i] = 0;
      }
  
      while ((c = getchar()) != EOF)
      {
          if (c &gt;= '0' &amp;&amp; c &lt;= '9')
              ++ndigit[c - '0'];
          else if (c == ' ' || c == '\n' || c == '\t')
              ++nwhite;
          else
              ++nother;
      }
  
      printf("digits = ");
  
      for (i = 0; i &lt; 10; i++)
  
      {
          printf(" %d", ndigit[i]);
      }
  
      printf(", white space = %d, other = %d\n", nwhite, nother);
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Sample Input:</strong></p>
  
  <pre><code>sample text for stackoverflow
  try 123
  123456789
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>digits =  0 2 2 2 1 1 1 1 1 1, white space = 7, other = 29
  Program ended with exit code: 0
  </code></pre>
  
  <hr>
  
  <p>I understand what the code is doing but I'm unable to understand how it's doing it.
  Why have we used <code>++ndigit[c - '0'];</code> in the code?</p>