Learn
Variables
The Increment and Decrement Operator
The increment and decrement operators are very useful when you need to increase or decrease the value of a variable by one.
The increment operator, represented by ++
, is used to add 1 to the value of a variable. For example:
In this example, the value of count
is initially 0. After executing count++
, the value is increased by 1, resulting in 1.
On the other hand, the decrement operator, represented by --
, is used to subtract 1 from the value of a variable. For example:
In this case, the initial value of quantity
is 5. After executing quantity--
, the value is decreased by 1, resulting in 4.
Instructions
Increment the value of x
by 1 using the increment operator (++
).
Print the updated value of x
to the console.
Sign up to start coding
Already have an account?
Sign In