I am confused about this code: (http://www.joelonsoftware.com/articles/CollegeAdvice.html)
while (*s++ = *t++);
What is the order of execution? Is *s = *t first done, and then are they each incremented? Or other way around?
Thanks.
EDIT: And what if it was:
while(*(s++) = *(t++));
and
while(++*s = ++*t);
From the precedence table you can clearly see
++is having higher precedence than*. But++is used here as post increment operator, so the incrementation happens after the assignment expression. So*s = *thappens first, then s and t are incremented.EDIT:
Is same as above. You are making it more explicit with the use of parenthesis. But remember
++is still a post increment.There is just one operator next to s. So
*is applied first and on that result++is applied which results in thelvalue requirederror.Again just operator next to s,t. So the incrementation happens first followed by copy. So we are effectively skipping the copy of the first char from t to s.