The i-- operator in C performs a post-subtraction operation, first assigns the value of i to a temporary variable, subtracts 1 and then updates the value of i. This is different from the prepended subtraction operator (i--), which updates the value of i before subtracting 1.
The post-increment and decrement operations represented by i-- in C
i-- in C The
operator represents a post-subtraction operation, which performs the following operations:
For example:
<code class="cpp">int i = 5; int j = i--; // j 为 5,i 为 4</code>
In the above example, after assigning the value of i to j, the value of i is decremented by 1. Therefore, the value of j is 5 and the value of i is 4.
The difference between the preceding subtraction operator (i--) and the preceding subtraction operator (i--)
The preceding subtraction operator (i--) will update i before subtracting 1 value, while i-- does the opposite.
For example:
<code class="cpp">int i = 5; int j = --i; // j 为 4,i 为 4 int k = i--; // k 为 4,i 为 3</code>
In the above example, --i decrements the value of i by 1 before updating the value of i, so the value of j is 4. On the other hand, i-- is decremented by 1 after assigning the value of i to k, so the value of k is 4 and the value of i is 3.
The above is the detailed content of What does i-- mean in c++. For more information, please follow other related articles on the PHP Chinese website!