Arithmetic Operators
This class of operators contain those operators which are used to perform arithmetic operation on the operands. They are binary operators i.e they act on two operands. They go like this:
Operator Symbol | Operator Name | Operator Description |
---|---|---|
+ | Addition | Use to add two operands |
– | Subtraction | Use to subtract two operands |
-expr | Unary Minus | It is Use to reverse the sign of the expression |
* | Multiply | Use to multiply two operands |
/ | Division | Use to divide two operands |
~/ | Division | Use to divide two operands but give output in integer(returns quotient) |
% | Modulus | Use to give remainder of two operands(returns remainder) |
Example showing the use of all Arithmetic Operator:
// Dart Program Demonstrating use
// Of all Arithmetic Operators
void main()
{
int a = 2;
int b = 3;
// Adding a and b
var c = a + b;
print("Sum (a + b) = $c");
// Subtracting a and b
var d = a - b;
print("Difference (a - b) = $d");
// Using unary minus
var e = -d;
print("Negation -(a - b) = $e");
// Multiplication of a and b
var f = a * b;
print("Product (a * b) = $f");
// Division of a and b
var g = b / a;
print("Division (b / a) = $g");
// Using ~/ to divide a and b
var h = b ~/ a;
print("Quotient (b ~/ a) = $h");
// Remainder of a and b
var i = b % a;
print("Remainder (b % a) = $i");
}
Output:
Sum (a + b) = 5
Difference (a - b) = -1
Negation -(a - b) = 1
Product (a * b) = 6
Division (b / a) = 1.5
Quotient (b ~/ a) = 1
Remainder (b % a) = 1
Operators in Dart
The operators are special symbols that are used to carry out certain operations on the operands. The Dart has numerous built-in operators which can be used to carry out different functions, for example, ‘+’ is used to add two operands. Operators are meant to carry operations on one or two operands.