The difference between i and i in C lies in the order of reading and incrementing the variable value: i: read the original value of i first, and then increment its value. i: First increment the value of i, and then read the incremented value.
The difference between i and i in C
In the C programming language, i and i are both suffix increments Operator used to increase the value of variable i by 1. However, there is a subtle but important difference between the two:
i :
i:
Example:
int i = 5; int j = i++; // j = 5, i = 6 int k = ++i; // k = 7, i = 7
In the above example, j increments the value of i from 5 to 6, but the expression j itself still has the value 5. On the other hand, i increments the value of i from 6 to 7, and the expression itself also has the value 7.
Usage scenarios:
To summarize, i and i are both postfix increment operators, but they differ in the order in which they read and increment variable values.
The above is the detailed content of The difference between i++ and ++i in c++. For more information, please follow other related articles on the PHP Chinese website!