I’m studying for my exam in programming languages, and I stumbled upon this (written in C):
*tp++ = *sp++;
I understood what *tp = *sp; might do, but here, when are the pointers incremented? before, after the values are fetched? in what order? I appreciate your answers
Since the
++operator comes after the variables, the values will be incremented after the expression is evaluated. So this will assign the value currently pointed to byspto the location currently pointed to bytp, then increment both pointers.If the expression was instead
Then the pointers would be incremented before evaluation.
These constructs commonly occur inside loops.