In C, the prefix increment (++ i) and postfix increment (i ++) operators are not the same operator.The prefix increment operator has higher precedence than the suffix increment.The results obtained at the same time are not completely consistent,So you need to distinguish

Let's look at the first

i is assigned 0, and i ++ (post ++) does not output 1.

Now i is assigned the value 0, ++ i, which is 1 before and after ++.

i is assigned a value of 0. In the case of ++, the value of i is incremented by 1 and the value of i is 1.

i is assigned 0, first followed by ++, and later ++ means that you are assigned first,After the assignment is completed, the statement is incremented by one after the statement ends. The first printf outputs the value 0 assigned to i at the beginning, and after the first printf is a (;) semicolon, which means the end of the statement. This statement ends,At this time i secretly adds 1 to it, and the second printf output is the value of i after the previous statement is processed.

i is assigned the value 0, i ++;this is a statement.Because there is a semicolon. We said that adding later means assigning values ​​first,Then wait for this statement to increase by one. i ++;The result of execution is 0 + 1=1. printf just outputs the value of i.

i is first assigned a value of 0, followed by a semicolon ";" after i ++ is the end of this statement, i ++;The result of processing is that the value of i after 0 + 1=1 is 1.

i is assigned a value of 0, ++ i;the former ++ is to add 1 to itself, and then assign it to itself. ++ i;The result of processing is 0 + 1=1.

i is assigned a value of 0 first, ++ i;(before ++) is that I first 0 + 1=1, and then assigned 1 to myself i becomes 1 i ++;(post ++) i has been assigned a value before 1, i ++;here is to first assign the value of the previous i to 1 to itself, but encountering a semicolon (;) means the end of this statement, The statement ends i ++;1 + 1=2 is executed.

i is assigned a value of 0, before ++, i becomes 1 i ++ in printf can only output the value 1 assigned by myself. If printf ("%d", i) is added below, the output of i Is for 2

to sum up:Before ++, add 1 by yourself, and assign to yourself after adding. After ++ is to assign the value yourself first,After the value is assigned, you must wait for the statement to finish before adding 1.

Tip:Before + after. This is what I think. It means:the first step is to add +1 first, then the first assignment is the last ++, the first assignment. In addition, the same principle applies before and after.

To sum up:++ is incremented by 1 before the operation, followed by incremented by 1

Examples are as follows.

int i=0;
printf ("%d", ++ i);i adds 1 before passing parameters,So the output is 1
parameters before printf ("%d", i ++),So still output the original value is 0
printf ("%d, i) because the above sentence adds 1 so the output is 1
  • Previous Access, creation, modification, deletion of DOM nodes in JavaScript
  • Next Understand the development of iOS multi-threaded applications and how to create threads