Home > Back-end >  The problem is why the answer is 20, please?
The problem is why the answer is 20, please?

Time:05-20

I think it's the 21st... Added a pointer to the value of the original is not with plus one?

CodePudding user response:

+ + behind, ascribed value + 1 again

CodePudding user response:

reference 1/f, rogue response:
+ + behind, value ascribed to + 1

On behalf of zhao four old wet point out that your two mistakes,

First, the expression of p - & gt; Age=p - & gt; The age + + behavior is undefined, the result of the final output could be 20, also may be 21,

+ + first, second, the said assignment again, this is without any basis,

Postfix increment the value of the expression is increasing in front of the original value, as well as the side effects of modifying operand stored value, so, on the whole, the expression of p - & gt; Age=p - & gt; Age + + has three basic action:

1, the computational expressions of p - & gt; The age + + values, the value is the original value of the structural members age 20;
2, the expression of p - & gt; Age + + launched a side effects, it can modify the structure members age stored value, changed to 21;
3, the expression of p - & gt; Age=p - & gt; Age + + launched a side effect, with the expression of p - & gt; The age + + change the value of the assignment operator to the left of the p - & gt; To the modification of page 20,
Note that the expression of p - & gt; Age=p - & gt; Age + + is to calculate a value, it is p - & gt; Page value after the assignment, but abandoned, so don't tube,

The above three movements occurred in what order? In accordance with the regulations, you must first calculate the value of the operand, overall, the first sub-expression p - & gt; Age + + values, the value is 20, so that the order of the three action might be
2 - & gt; 1 - & gt; 3
May also be a
2 - & gt; 3 - & gt; 1
Age no matter what kind of order, members will be written twice, but the end result is different, if it is the first order, so, the age of the final value is 20 members; If it is the second order members age of the final value is 21,
  • Related