Types of Assignment Operators
- Simple Assignment Operator (
=
) - Addition Assignment Operator (
+=
) - Subtraction Assignment Operator (
-=
) - Multiplication Assignment Operator (
*=
) - Division Assignment Operator (
/=
) - Modulus Assignment Operator (
%=
)
Below is a table summarizing common assignment operators along with their symbols, description, and examples:
Operator | Description | Examples |
---|---|---|
= (Assignment) | Assigns the value on the right to the variable on the left. | x = 10; assigns the value 10 to the variable x. |
+= (Addition Assignment) | Adds the value on the right to the current value of the variable on the left and assigns the result to the variable. | x += 5; is equivalent to x = x + 5; |
-= (Subtraction Assignment) | Subtracts the value on the right from the current value of the variable on the left and assigns the result to the variable. | y -= 3; is equivalent to y = y - 3; |
*= (Multiplication Assignment) | Multiplies the current value of the variable on the left by the value on the right and assigns the result to the variable. | z *= 2; is equivalent to z = z * 2; |
/= (Division Assignment) | Divides the current value of the variable on the left by the value on the right and assigns the result to the variable. | a /= 4; is equivalent to a = a / 4; |
%= (Modulo Assignment) | Calculates the modulo of the current value of the variable on the left and the value on the right, then assigns the result to the variable. | b %= 3; is equivalent to b = b % 3; |
Assignment Operators in Programming
Assignment operators in programming are symbols used to assign values to variables. They offer shorthand notations for performing arithmetic operations and updating variable values in a single step. These operators are fundamental in most programming languages and help streamline code while improving readability.
Table of Content
- What are Assignment Operators?
- Types of Assignment Operators
- Assignment Operators in C
- Assignment Operators in C++
- Assignment Operators in Java
- Assignment Operators in Python
- Assignment Operators in C#
- Assignment Operators in Javascript
- Application of Assignment Operators
Contact Us