Increment and Decrement Operators

Increment and decrement operators are used to increase or decrease the value of a variable by 1.

The increment operator ++ adds 1 to the variable, and the decrement operator -- subtracts 1 from the variable.

Here's an example:

Loading...

These operators can also be used before the variable (pre-increment/decrement) or after the variable (post-increment/decrement), which affects when the value is changed.

Pre-increment/decrement changes the value before any other operations are performed, while post-increment/decrement changes the value after all other operations are performed.

Here's an example:

Loading...

In this example, the value of num2 is incremented before the assignment is performed. So, num1 is assigned the value of num2, which is 1.

Loading...

In this example, the value of num2 is incremented after the assignment is performed. So, num1 is assigned the value of num2, which is 0.


In the exercises below, you'll have a variable called x assigned to 5. Select all the options that will allow to make the y variable equal to 6.

Loading...