- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Assignment operators in Dart Programming
We make use of assignment operators whenever we want to assign values to a variable. There are times when we combine assignment operators with arithmetic operators and logical operators to build a shorthand version of both the assignment and arithmetic (or logical) expression. These shorthand versions are also known as compound statements.
In the table below, all the assignment operators that are present in dart are mentioned.
Consider the table shown below −
Operator | Description | Expression |
---|---|---|
= | Assignment operator | a = b |
+= | Add and assign combined | a += b is equivalent to a = a + b |
-= | Subtract and assign | a –= b is equivalent to a = a - b |
*= | Multiply and assign | a *= b is equivalent to a = a * b |
/= | Divide and assign | a /= b is equivalent to a = a / b |
~/= | Divide and assign and store Int value | a ~/= b is equivalent to a = a ~/ b |
%= | Modulus and assign | a %= b is equivalent to a = a % b |
<<= | Left shift and and assign | a <<= 3 is equivalent to a = a << 3 |
>>= | Right shift and assign | a >>= 3 is equivalent to a = a >> 3 |
&= | Bitwise AND assign | a &= 3 is equivalent to a = a & 3 |
^= | Bitwise exclusive OR and assign | a ^= 3 is equivalent to a = a ^ 3 |
|= | Bitwise inclusive OR and assign | a |= 3 is equivalent to a = a | 3 |
Let's make use of all the above mentioned assignment operators in a dart program.
Example
Consider the example shown below −
void main(){ var x = 10; print("x = 10 -> ${x}"); x += 15; print("x += 15 -> ${x}"); x -= 10; print("x -= 10 -> ${x}"); x *= 10; print("x *= 10 -> ${x}"); x ~/= 5; print("x /= 5 -> ${x}"); x %= 7; print("x %= 7 -> ${x}"); x <<= 2; print("x <<= 2 -> ${x}"); x >>= 3; print("x >>= 3 -> ${x}"); x &= 2; print("x &= 2 -> ${x}"); x ^= 5; print("x ^= 5 -> ${x}"); x |= 10; print("x |= 10 -> ${x}"); }
Output
x = 10 -> 10 x += 15 -> 25 x -= 10 -> 15 x *= 10 -> 150 x /= 5 -> 30 x %= 7 -> 2 x <<= 2 -> 8 x >>= 3 -> 1 x &= 2 -> 0 x ^= 5 -> 5 x |= 10 -> 15
- Related Articles
- Arithmetic operators in Dart Programming
- Bitwise operators in Dart Programming
- Relational Operators in Dart Programming
- Null Aware Operators in Dart Programming
- Test type operators in Dart Programming
- Assignment Operators in C++
- Perl Assignment Operators
- Java Assignment Operators
- Python Assignment Operators
- Compound assignment operators in C#
- Compound assignment operators in Java
- Compound Assignment Operators in C++
- Comments in Dart Programming
- Constructors in Dart Programming
- Enumerations in Dart Programming

Advertisements