Decrement Operators
Decrement operators are used in programming languages to decrease the value of a variable by one. Similar to increment operators, there are two types of decrement operators: the prefix decrement operator (–x) and the postfix decrement operator (x–).
Prefix Decrement Operator (–x):
- The prefix decrement operator decreases the value of the variable by 1 before the value is used in the expression.
- Syntax:
--x
- Example: If
x
is initially 5,--x
will decrementx
to 4 and return the new value (4).
Postfix Decrement Operator (x–):
- The postfix decrement operator decreases the value of the variable by 1 after the value is used in the expression.
- Syntax:
x--
- Example: If
x
is initially 5,x--
will return the current value ofx
(5) and then decrementx
to 4.
Increment and Decrement Operators in Programming
Increment and Decrement Operators are Unary Operators commonly used in programming to increase or decrease the value of a variable by one, respectively. They provide a shorthand way to perform these common operations.
Table of Content
- Increment Operators
- Increment Operators in C
- Increment Operators in C++
- Increment Operators in Java
- Increment Operators in Python
- Increment Operators in C#
- Increment Operators in Javascript
- Decrement Operators
- Decrement Operators in C
- Decrement Operators in C++
- Decrement Operators in Java
- Decrement Operators in Python
- Decrement Operators in C#
- Decrement Operators in Javascript
- Difference between Increment and Decrement Operator