Home  >  Article  >  Backend Development  >  In c language--what does it mean?

In c language--what does it mean?

下次还敢
下次还敢Original
2024-04-29 22:33:14890browse

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.

In c language--what does it mean?

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:

  • post-decrement : x--, decrements x by 1, and returns the original value.
  • Prefix decrement: --x, 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn