Let's start with *p += 1
I will try to answer this a little differently ... Step 1 Let's look at the operators and operands: in this case it is one operand (pointer p), and we have two operators: this case * for dereference and + = 1 for increment. Step 2, which has a higher priority *, has a higher priority over + =
*P++ This is a little more complicated ... maybe even evil Again we have one operand (p pointer) and two operators, only now * for dereferencing and postposition ++ have the same priority. (In some tables, ++ in the message is a higher priority.)
Step 1. Look at the operators and operands: in this case it is an operand, and you have two operators, in this case * for dereferencing and ++ for incrementing. Step 2, which has a higher priority? ++ takes precedence over * Note: even if they HAVE ANY INITIAL MANAGEMENT, they bind right to left, again ++ to * Step 3 (the hard part ...) Where is ++? it is on the right side of the operand, which means POST Increment . In this case, the compiler takes a βmental noteβ to perform the increment AFTER it is done with all other operators ... What after? This means that he will only apply the increment as the very last step before the next ';' so this will be done with all other operators that are on the same line, note: if it was * ++ p, then it will do this BEFORE any other operator on the same line, so in this case it is equivalent to taking two processor registers, one will hold the value of dereferenced * p and the other will hold the value of incremented p ++, the reason in this case is two, it is POST activity ... Here, in this case, it is difficult, and this looks like a contradiction. One would expect ++ to take precedence over *, which does only that POST means that it will only be applied after ALL other operands, BEFORE the next one :; marker...
As I said, the tricky part is that any increment to the right of the operand will be delayed and will be used as a LAST operation before it moves to the next line ...
G. Simsic May 2, '17 at 13:13 2017-05-02 13:13
source share