- Dart Programming - Home
- Dart Programming - Overview
- Dart Programming - Environment
- Dart Programming - Syntax
- Dart Programming - Data Types
- Dart Programming - Variables
- Dart Programming - Operators
- Dart Programming - Loops
- Dart Programming - Decision Making
- Dart Programming - Numbers
- Dart Programming - String
- Dart Programming - Boolean
- Dart Programming - Lists
- Dart Programming - List Operations
- Dart Programming - Map
- Dart Programming - Symbol
- Dart Programming - Runes
- Dart Programming - Enumeration
- Dart Programming - Functions
- Dart Programming - Interfaces
- Dart Programming - Classes
- Dart Programming - Object
- Dart Programming - Collection
- Dart Programming - Generics
- Dart Programming - Packages
- Dart Programming - Exceptions
- Dart Programming - Debugging
- Dart Programming - Typedef
- Dart Programming - Libraries
- Dart Programming - Async
- Dart Programming - Concurrency
- Dart Programming - Unit Testing
- Dart Programming - HTML DOM
Dart Programming Useful Resources
Dart Programming - Assignment Operators
Assignment Operators
The following table lists the assignment operators available in Dart.
| Sr.No | Operator & Description |
|---|---|
| 1 | =(Simple Assignment )
Assigns values from the right side operand to the left side operand Ex:C = A + B will assign the value of A + B into C |
| 2 | ??=
Assign the value only if the variable is null |
| 3 | +=(Add and Assignment)
It adds the right operand to the left operand and assigns the result to the left operand. Ex: C += A is equivalent to C = C + A |
| 4 | =(Subtract and Assignment)
It subtracts the right operand from the left operand and assigns the result to the left operand. Ex: C -= A is equivalent to C = C - A |
| 5 | *=(Multiply and Assignment)
It multiplies the right operand with the left operand and assigns the result to the left operand. Ex: C *= A is equivalent to C = C * A |
| 6 | /=(Divide and Assignment)
It divides the left operand with the right operand and assigns the result to the left operand. |
Note − Same logic applies to Bitwise operators, so they will become <=, >=, |= and ^=.
Usage of Assignment Operators
Example
The following example shows how you can use the assignment operators in Dart −
void main() {
var a = 12;
var b = 3;
a+=b;
print("a+=b : ${a}");
a = 12; b = 13;
a-=b;
print("a-=b : ${a}");
a = 12; b = 13;
a*=b;
print("a*=b' : ${a}");
a = 12; b = 13;
a/=b;
print("a/=b : ${a}");
a = 12; b = 13;
a%=b;
print("a%=b : ${a}");
}
Output
It will produce the following output −
a+=b : 15 a-=b : -1 a*=b' : 156 a/=b :0.9230769230769231 a%=b : 12