178k views
4 votes
What is the difference between pre/postfix increment (i.e. ++a vs a++)?

1) Pre-increment adds 1 to the value of a and then returns the updated value. Post-increment returns the original value of a and then adds 1 to it.
2) Pre-increment returns the original value of a and then adds 1 to it. Post-increment adds 1 to the value of a and then returns the updated value.
3) Pre-increment adds 1 to the value of a and then returns the updated value. Post-increment adds 1 to the value of a but returns the original value.
4) Pre-increment returns the original value of a and then adds 1 to it. Post-increment returns the updated value of a after adding 1 to it.

User Zubatman
by
8.6k points

1 Answer

3 votes

Final answer:

Pre-increment adds 1 to the value of a and then returns the updated value. Post-increment returns the original value of a and then adds 1 to it.

Step-by-step explanation:

The difference between pre/postfix increment (i.e. ++a vs a++) is as follows:

  1. Pre-increment adds 1 to the value of a and then returns the updated value. Post-increment returns the original value of a and then adds 1 to it.
  2. Pre-increment returns the original value of a and then adds 1 to it. Post-increment adds 1 to the value of a and then returns the updated value.
  3. Pre-increment adds 1 to the value of a and then returns the updated value. Post-increment adds 1 to the value of a but returns the original value.
  4. Pre-increment returns the original value of a and then adds 1 to it. Post-increment returns the updated value of a after adding 1 to it.

User Thomas Vervik
by
7.9k points