The --a operator in C is a unary decrement operator, which decrements the value of variable a by 1. Divided into prefix operators and postfix operators, the former uses the value after decrement, and the latter uses the value before decrement.
The meaning of --a in C
In C, --a is A unary decrement operator that decrements the value of variable a
by one.
Usage:
--a can be used as a prefix operator or a postfix operator:
--a
First decrement a
by 1, and then assign the result to a
. For example: <code class="cpp">int a = 5; --a; // 结果为 a = 4</code>
a--
Return the value of a
first, and then a
Decrement by 1. For example: <code class="cpp">int a = 5; int b = a--; // 结果为 b = 5, a = 4</code>
Difference:
Prefix decrement and suffix decrement differ in the time used for variables:
Example:
<code class="cpp">int a = 5; cout << --a << endl; // 输出:4(前缀递减) cout << a-- << endl; // 输出:4(后缀递减) cout << a << endl; // 输出:3(后缀递减后)</code>
The above is the detailed content of What does --a mean in c++. For more information, please follow other related articles on the PHP Chinese website!