An operator defines how the operands (which represent data) will be processed to produce a value. These are remarkable signs that are utilised to do the specific procedures on the operands. Dart has various implicit operators which can be utilised to complete various capabilities.
There are various types of operators available in dart, They are
Arithmetic Operator
Relational Operators
Bitwise Operators
Assignment Operators
Logical Operators
Conditional Operators
Cascade Operators
Type test Operators
let us take a look into it operators in detail.
whenever we implement any logical activity with numbers we adopt these operators.
If it's not too much trouble, actually look at underneath table for nitty gritty data on Arithmetic Operators.
Here is the example for Arithmetic Operator
void main() {
int a = 10;
int b = 5;
// Summation Operator ( + )
int sum = a+b;
print('Sum of a & b is:...$sum');
// Sum of a & b is:...15
// Subtraction Operator ( - )
int diff = a-b;
print('Difference between a & b is.......$diff');
// Difference between a & b is.......5
// multiplication operator ( * )
int mul = a * b;
print('Multiplication of a & b is.....$mul');
// Divison Operator ( / )
double div = a / b;
print('Divison of a & b is....${div}');
// Divison of a & b is....2
// Modulus Operator
int mod = a % b;
print('Modulus of a & b is.....$mod');
// Modulus of a & b is.....0
// Using ~/ divide i & j
int quo = a ~/ b;
print('Quotient of a & b is....${quo}');
// Quotient of a & b is....2
// Incremental Function
a++;
print('Incremental value of a ......${a}');
// Incremental value of a ......11
// Decremental Function
b--;
print('Decremental value of b.....${b}');
// Decremental value of b.....4
}
For characterising a connection between two elements we utilise this operator. These operators returns generally a boolean worth (True/False).
To characterise a balance of a dart operators the stream is here
== For checking the factors both are equivalent
!= For checking the factors which are not equivalent
Alongside correspondence check a few times we want to confirm different relations between the components
> This is the more prominent than image, which states Left operand is more noteworthy than the right operand.
< This is the lesser than image, which states Left operand is lesser than the right operand
>= This Greater or equivalent case. it imply that condition or a case the left operand is more prominent or equivalent to a right operand.
<= This is Lesser or equivalent case. That's what it intend, the left operand is lesser or equivalent to right operand.
Here is the example for relational operator
void main() {
// Equality Operator
int a = 5; int b = 5;
print('Get value where a is equal to b => ${a==b} ');
// Get value where a is equal to b => true
// Not Equal operator
print('Verify the condition where a is not equal to b => ${a != b}');
// Verify the condition where a is not equal to b => false
int c =10; int d = 20;
print('Greater value check between c & d ${c>d}');
// Greater value verification between c & d false
print('Lesser value check between c & d ${c<d}');
// Lesser value check between c & d true
// Greater than or equal case
print('Greater than or equal case between a & b ${a>=b}');
// Lesser than or equal case
print('Less than or equal case between a & b ${c<=b}');
}
These operators are used to perform Bitwise operations on operands.
For assigning values to variables we can use these operators. these can be used for combing of arithmetic operators.
void main() {
int a = 5;
int b = 10;
a+=b;
print("a+=b Value : ${a}");
// a+=b : 15
a-=b;
print("a-=b Value : ${a}");
// a-=b : 5
a*=b;
print("a*=b' Value : ${a}");
// a*=b : 50
a/=b;
print("a/=b Value : ${a}");
// a/=b : 5
a%=b;
print("a%=b Value : ${a}");
// a%=b : 5
}
These are used to verify combine two or more conditions logically. Logical operators return a Boolean value.
There are three types of operators are available in logical operators. they're And( && ), Or ( || ) & Not ( ! ).
And operator will return true when all the conditions specified are true.
Or this operator will return true value at least one condition is true.
Not this operator will be consider, for implementing inverse of a condition
An example for And condition
void main() {
int a = 5, b= 10;
bool result = (a<b && (b-a)>=a);
print(result);
}
// true
in the above example we are considering two integer variables a & b with values 5, 10 & we are passing these values into below condition which is stating that a is lesser than b and the difference between b and a is greater than or equal to value of a. when the both the conditions were satisfied the result will be true or else it is false.
Now take another example on OR condition.
void main() {
int a = 5, b= 10;
bool result = (a<b || (b-a)<a);
print(result);
}
// true
We are reusing by changing the condition from And ( && ) to OR ( || ). Lets split the condition into two parts the first of the condition which the value of a is lesser than the value of b which is true and the other part of the condition the difference between b and a is lesser than the value of a which is false. as we are using OR condition it'll check at least one statement should be true. finally it'll print the result as true.
Now take look on Not operator.
void main() {
int a = 5, b= 10;
// Using not operator
bool res = !(a>b);
print(res);
}
// true
We can discuss on this operators when we're discussing on conditional statements.
It is too early to discuss on cascade operators we can have a word while we're discussing on Object declaration in OOPS concepts.