Home >Backend Development >C#.Net Tutorial >What is the difference between x++ and ++x in c language

What is the difference between x++ and ++x in c language

王林
王林Original
2020-05-10 15:21:3537527browse

What is the difference between x++ and ++x in c language

The difference is as follows:

x means that the value of x is incremented by 1 first, and then the value of x is calculated.

x is to first calculate the value of x, and then increase the value of x by 1.

Example:

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

The first one outputs 10, x first uses the value of x in the current expression, and then increases the value of x by 1, and the second one outputs 11, because After the previous instruction, x has increased by 1.

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 tutorial: c language tutorial

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