title: C pointers: difference between while(*s++) { ;} and while(*s) { s++;}
body: <p>I'm going through K &amp; R, and am having difficulty with incrementing pointers. Exercise 5.3 (p. 107) asks you to write a strcat function using pointers. </p>
  
  <p>In pseudocode, the function does the following:</p>
  
  <ol>
  <li>Takes 2 strings as inputs.</li>
  <li>Finds the end of string one.</li>
  <li>Copies string two onto the end of string one.</li>
  </ol>
  
  <p>I got a working answer:</p>
  
  <pre><code>void strcats(char *s, char *t)
  {
      while (*s)            /* finds end of s*/
          s++;
      while ((*s++ = *t++)) /* copies t to end of s*/
          ;
  }
  </code></pre>
  
  <p>But I don't understand why this code doesn't also work:</p>
  
  <pre><code>void strcats(char *s, char *t)
  {
      while (*s++)
          ;
      while ((*s++ = *t++))
          ;
  }
  </code></pre>
  
  <p>Clearly, I'm missing something about how pointer incrementation works. I thought the two forms of incrementing s were equivalent. But the second code only prints out string s. </p>
  
  <p>I tried a dummy variable, i, to check whether the function went through both loops. It did. I read over the sections 5.4 and 5.5 of K &amp; R, but I couldn't find anything that sheds light on this.</p>
  
  <p>Can anyone help me figure out why the second version of my function isn't doing what I would like it to? Thanks!</p>
  
  <p>edit: Thanks everyone. It's incredible how long you can stare at a relatively simple error without noticing it. Sometimes there's no better remedy than having someone else glance at it.</p>