title: Understanding character pointers in a while loop
body: <p>I am learning C and a I came across this function in my study materials. The function accepts a string pointer and a character and counts the number of characters that are in the string.  For example for a string <code>this is a string</code> and a <code>ch = 'i'</code> the function would return <code>3</code> for 3 occurrences of the letter <code>i</code>. </p>
  
  <p>The part I found confusing is in the while loop.  I would have expected that to read something like <code>while(buffer[j] != '\0')</code> where the program would cycle through each element <code>j</code> until it reads a null value.  I don't get how the while loop works using <code>buffer</code> in the while loop, and how the program is incremented character by character using <code>buffer++</code> until the null value is reached.  I tried to use debug, but it doesn't work for some reason.  Thanks in advance.</p>
  
  <pre><code>int charcount(char *buffer, char ch)
  {
  int ccount = 0;
  while(*buffer != '\0')
  {
      if(*buffer == ch)
          ccount++;
      buffer++;
  }
  return ccount;  
  }
  </code></pre>