Skip to content
CampusEduX

Pre- vs Post-Increment

Mediumjava
Learn the Concept: Unary Operators

Read an integer x. Simulate both forms of increment starting from x and print what each produces.

  • Post-increment: r1 = a++ — r1 gets the old value, then a becomes x + 1.
  • Pre-increment: r2 = ++b — b becomes x + 1 first, then r2 gets the new value.

Input: one integer x.

Output: two lines:

<r1> <a>
<r2> <b>

Related Problems

Input (stdin)

Output

Run your code to see output here...