Home >Backend Development >C++ >What does i++ mean in c++
In C, i is the postfix increment operator, which increases the value of variable i by 1. Its working principle is to first take out the current value of the variable and then increment it by 1. It does not return a new value, so i needs to be used to print the new value. Examples include: int i = 5; i ; // i becomes 6; int j = i ; // i becomes 7, j becomes 6.
What is i
In C, i is a postfix increment operator used to increment the variable i The value is increased by 1.
How to use i
i operator is usually placed after the variable i, for example:
<code class="cpp">int i = 0; i++; // 将 i 的值从 0 增加到 1</code>
How i works## The
#i operator performs the following two operations:<code class="cpp">cout << i++; // 输出 0,而不是 1</code>Instead, i can be used like this to print the new value:
<code class="cpp">cout << ++i; // 输出 1</code>
Example
Here is A few examples of i:<code class="cpp">int i = 5; i++; // i 的值变为 6 int j = i++; // i 的值变为 7,j 的值变为 6</code>
Note
i is a postfix operator, which means it increments the variable only after evaluating the expression. The opposite is the prefix increment operator i, which increments the variable before evaluating the expression.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!