title: C string to uppercase in C and C++
body: <p>While I was putting together a to-uppercase function in C++ I noticed that I did not receive the expected output in C.</p>
  
  <p><strong>C++ function</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cctype&gt;
  #include &lt;cstdio&gt;
  
  void strupp(char* beg)
  {
      while (*beg++ = std::toupper(*beg));
  }
  
  int main(int charc, char* argv[])
  {
      char a[] = "foobar";
      strupp(a);
      printf("%s\n", a);
      return 0;
  }
  </code></pre>
  
  <p>Output as expected:</p>
  
  <pre><code>FOOBAR
  </code></pre>
  
  <p><hr>
  <strong>C function</strong></p>
  
  <pre><code>#include &lt;ctype.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  void strupp(char* beg)
  {
      while (*beg++ = toupper(*beg));
  }
  
  int main(int charc, char* argv[])
  {
      char a[] = "foobar";
      strupp(a);
      printf("%s\n", a);
      return 0;
  }
  </code></pre>
  
  <p>The output is the expected result with the first character missing</p>
  
  <pre><code>OOBAR
  </code></pre>
  
  <p>Does anyone know why the result gets truncated while compiling in C?</p>