In C language, "--" is the decrement operator, which is used to decrement the variable value by 1. Post-decrement returns the original value first and then decrements, and pre-decrement first decrements and then returns the value. It is suitable for variables, but not for constants or strings.
The meaning of --
in C language is
--
Is the decrement operator in C language, used to reduce the value of a variable by 1. It is a unary operator, which means it only acts on one operand.
Usage method
##-- can be used in two ways:
, decrements
x by 1, and returns the original value.
, decrement
x by 1, and then return the value minus 1.
Example
<code class="c">int x = 10; x--; // 后置递减,x 变成 9 cout << x; // 输出 9 --x; // 前置递减,x 变成 8 cout << x; // 输出 8</code>
The difference between post-decrement and pre-decrement
Post-decrement returns to the original first value, and then perform the decrement operation, while the prefix decrement first performs the decrement operation, and then returns the value minus 1. This can make a difference in certain circumstances.Note
cannot be used for constants or strings.
can also be used with pointers, but it decrements the address pointed to by the pointer.
The above is the detailed content of In c language--what does it mean?. For more information, please follow other related articles on the PHP Chinese website!