What is an operator?

Operator is an symbol in programming that performsn an operation on operands

Syntax

operand1 operator operand2

There are two types of operators.

  • Binary Operator: It operates on two operands such as addition, subtraction, multiplication, division, and modulus
  • unary operator: It operats on single operand such as increment and decrement

Dart supports multiple operators

  • Arithmetic Operators
  • Relational Operators
  • Assignment Operators
  • Logical Operators
  • Bitwise Operators
  • Other Operators

Dart Arithmetic Operators

Arithmetic operators in Dart provide arithmetic operations such as add, division, subtraction, and division multiplication operators.

OperatorTitleDescriptionExample
+Additionaddition of two or more operandsp+q=50
-Subtractionsubtraction of two or more operandsq-p=10
*Multiplicationmultiplication of two or more operandsp*q=600
/Divideresults quotient after the division of valuesq/p=1.5
%ModulusReturn the remainder after the division of valuesq%p=10
%ModulusReturn the remainder after the division of valuesq%p=10
-exprUnary Minusreverse of an expression-(10-7) is -3
~/Division Intreturns division int value(10~/7) is 1
++IncrementIncrement the value by 1++p=21
--DecrementDecrement the value by 1--q=29

Here is an arithmetic operator example

void main() {
  var m = 25;
  var n = 4;
  print("m+n - ${m + n}");
  print("++m - ${++m}");
  print("m++ - ${m++}");
  print("--m - ${--m}");
  print("m-- - ${m--}");
  print("m-n - ${m - n}");
  print("m/n - ${m / n}");
  print("m*n - ${m * n}");
  print("m%n - ${m % n}");
  print("m~/n - ${m ~/ n}");
}

Output:

m+n - 29
++m - 26
m++ - 26
--m - 26
m-- - 26
m-n - 21
m/n - 6.25
m*n - 100
m%n - 1
m~/n - 6