Home  >  Article  >  Backend Development  >  C language--the difference between x and x--

C language--the difference between x and x--

Guanhui
GuanhuiOriginal
2020-06-03 16:17:3231533browse

C language--the difference between x and x--

The difference between C language--x and x--

The difference between "--x" and "x--" in C language : The former is called a prefix operation, while the latter is a postfix operation. The prefix operation is to perform the operation first, and then add 1 to the variable x. The postfix operation is to first add 1 to the variable x, and then perform the operation. The result is the same.

Example:

int x=10;
System.out.println(x++);  
System.out.println(x);

The first output is 10, x first uses the value of x in the current expression, and then increments the value of x 1, the second output is 11, because x has increased by 1 after the previous instruction.

int x=10;
System.out.println(++x);
System.out.println(x);

The first one outputs 11, x first increments the value of x by 1, and then uses the value of x in the current expression. The second one also outputs 11, and x increases after the previous instruction. 1.

Recommended tutorials: "PHP Tutorial" "C#"

The above is the detailed content of C language--the difference between x and x--. 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