++ And -- both operators are single-object operators, which have the right combination (that is, the combination of priority and the variable on the right of the operator), and their priority is higher than other arithmetic operators. When the ++ or -- operator is placed on the left of the variable, it is called a prefix operation, indicating that the value of the variable is used after the auto-increment or auto-subtraction operation, when the ++ or -- operator is placed on the right of a variable, it is called a post-operation, indicating that the value of the variable is referenced before auto-increment or auto-subtraction.
For example, if I = 1, j = 2, The ++ I + j -- operation is performed first, And I = 2 is obtained, then perform the j -- operation. According to the post-operation rules, the system adds the original value 2 of J and the new value 2 of I, and then performs the j --, and obtains j = 1. therefore, the expression value is 4.
Private void hellofrm_load (Object sender, eventargs E)
{
Int I = 1, j = 1, p, q;
P = (I ++) + (I ++ );
Q = (++ J) + (++ J );
Label1.text = "I value:" + I + ",";
Label1.text + = "J:" + J + ",";
Label1.text + = "P value:" + P + ",";
Label1.text + = "Q:" + q;
}
Result After running: the value of I is 4, the value of J is 4, the value of P is 6, and the value of Q is 9.