title: The difference between C and C++ regarding the ++ operator
body: <p>I have been fooling around with some code and saw something that I don't understand the "why" of.</p>
  
  <pre><code>int i = 6;
  int j;
  
  int *ptr = &amp;i;
  int *ptr1 = &amp;j
  
  j = i++;
  
  //now j == 6 and i == 7. Straightforward.
  </code></pre>
  
  <p>What if you put the operator on the left side of the equals sign?</p>
  
  <pre><code>++ptr = ptr1;
  </code></pre>
  
  <p>is equivalent to</p>
  
  <pre><code>(ptr = ptr + 1) = ptr1; 
  </code></pre>
  
  <p>whereas</p>
  
  <pre><code>ptr++ = ptr1;
  </code></pre>
  
  <p>is equivalent to</p>
  
  <pre><code>ptr = ptr + 1 = ptr1;
  </code></pre>
  
  <p>The postfix runs a compilation error and I get it. You've got a constant "ptr + 1" on the left side of an assignment operator. Fair enough. </p>
  
  <p>The prefix one compiles and WORKS in C++. Yes, I understand it's messy and you're dealing with unallocated memory, but it works and compiles. In C this does not compile, returning the same error as the postfix "lvalue required as left operand of assignment". This happens no matter how it's written, expanded out with two "=" operators or with the "++ptr" syntax.</p>
  
  <p>What is the difference between how C handles such an assignment and how C++ handles it?</p>