<h2>Pre-Increment increments the value immediately, Post increment increments the value only after executing the entire line.</h2>
Explanation:
class PrePostIncOperator {
public static void main(String[] args){
int x=5;
System.out.println(x++);
System.out.println("\n"+ ++x);
}
}
Let us understand the program.
int x = 5 => Initializes the value of 5 to the variable x
System.out.println(x++); This is the post increment operator. The value of x gets incremented only after printing the value. That is first System.out.println(x) will be executed and then the increment operator takes place once it finds the ";" that is the end of the statement. The memory which holds the value of x is changed only after executing the statement.
System.out.println("\n"+ ++x);
Here the value gets incremented and immediately assigns to the memory.