Home >Backend Development >C#.Net Tutorial >The difference between x++ and x+ in c language
The difference between x and x in C language: x: post-increment operator, first assign the value of x to the expression, and then add 1 to x. x: Addition operator, adds x to the specified value and assigns the result to the expression.
The difference between x and x in C language
x and x are two different things in C language operators, which act differently on the variable x.
x: Post-increment operator
x: The addition operator
Example:
<code class="c">int x = 5; printf("x++ = %d\n", x++); // 输出5 printf("x = %d\n", x); // 输出6 int y = 5; printf("x+ = %d\n", x+); // 输出10 printf("x = %d\n", x); // 输出5</code>
In the first example, x first assigns the value of x (5) to the expression, and then the value of x Increase by 1. Therefore, printf outputs 5. After that, the value of x becomes 6.
In the second example, x adds the value of x (5) to a given value (5) and assigns the result (10) to the expression. Therefore, printf outputs 10. However, the value of x still remains 5.
The above is the detailed content of The difference between x++ and x+ in c language. For more information, please follow other related articles on the PHP Chinese website!