Obviously, post-increment has higher priority than pre-increment. That is to say, calculate firsta++然后才是++a.
So why does this operation expression end up as 2 + 2? 2 + 2? 因为这俩运算都比+运算优先级高。 然后,虽然a++先运算,但是a自增要等到整个算式运算结束,而++a则是马上就自增。 a++和++a运算之后,+运算之前,a的值就是2。 最后整个算式运算结束,a才会自增到3Because these two operations have higher priority than the + operation.
Then, although a++ is calculated first, the increment of a has to wait until the entire calculation is completed, while ++a is incremented immediately. . 🎜After the a++ and ++a operations, but before the + operation, the value of a is 2. 🎜Finally, when the entire calculation is completed, a will increase to 3. You can print it out and take a look. 🎜
Read the documentation first: operator precedence
Obviously, post-increment has higher priority than pre-increment.
That is to say, calculate first
a++
然后才是++a
.So why does this operation expression end up as
Then, although2 + 2
?2 + 2
?因为这俩运算都比
+
运算优先级高。然后,虽然
a++
先运算,但是a
自增要等到整个算式运算结束,而++a
则是马上就自增。a++
和++a
运算之后,+
运算之前,a
的值就是2
。最后整个算式运算结束,
a
才会自增到3
Because these two operations have higher priority than the+
operation.a++
is calculated first, the increment ofa
has to wait until the entire calculation is completed, while++a
is incremented immediately. . 🎜After thea++
and++a
operations, but before the+
operation, the value ofa
is2. 🎜Finally, when the entire calculation is completed,
a
will increase to3
. You can print it out and take a look. 🎜