155k views
5 votes
Explain the difference between the prefix and postfix forms of the increment operator.

User Nita
by
5.5k points

1 Answer

6 votes

Answer:

The prefix form of increment operator is ++a, for the variable a.

  • it first increments the value of the variable and substitutes the incremented value of the variable to the expression.

The postfix form of increment operator is a++, for the variable a.

  • it substitutes the existing value of the variable to the expression and then increments the value.

Step-by-step explanation:

Let a = 6.

++a + 5 = 12.

but

a++ + 5 =11.

User Fdhex
by
5.0k points