70.6k views
2 votes
What is pre increment and post increment in java?

User Krischan
by
7.1k points

1 Answer

3 votes

Final answer:

Pre-increment and post-increment are unary operators used to increment the value of a variable by 1 in Java.

Step-by-step explanation:

In Java, pre-increment and post-increment are unary operators used to increment the value of a variable by 1.

The pre-increment operator (++i) increments the value of the variable and then returns the incremented value. For example, if i is 5, the expression ++i would evaluate to 6.

The post-increment operator (i++) returns the value of the variable and then increments it. Using the same example, if i is 5, the expression i++ would evaluate to 5, and the value of i would become 6 after the evaluation.

User PeterAllenWebb
by
7.0k points