Home >Backend Development >C++ >In c++--what does it mean?
The -- operator in C is a unary subtraction operator, used to subtract 1 from the value of a variable or expression. It has two forms: pre-decrement and post-decrement: pre-decrement (--): decrement by 1 first, and then use the value of the variable. Post-decrement (--): Use the value of the variable first, then decrement it by 1.
The -- operator in C
In the C programming language, the -- operator is a unary subtraction operator, used to reduce the value of a variable or expression by 1.
Usage:
<code class="cpp">--variable; // 前置递减 variable--; // 后置递减</code>
Difference:
Example:
<code class="cpp">int x = 5; // 前置递减 --x; // 减 1 并赋值给 x,此时 x 的值变为 4 cout << x << endl; // 输出:4 // 后置递减 x--; // 先使用 x 的值(5),再减 1,此时 x 的值变为 4 cout << x << endl; // 输出:4</code>
Priority:
-- Operators have higher priority than arithmetic operations symbols (e.g., -, *, /), but lower than brackets and unary signs (and -).
Note:
The above is the detailed content of In c++--what does it mean?. For more information, please follow other related articles on the PHP Chinese website!