What is an operator?

There are two types of operators

  • Binary Operator
  • unary operator

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.

Operator Title Description Example
+ Addition addition of two or more operands p+q=50
- Subtraction subtraction of two or more operands q-p=10
* Multiplication multiplication of two or more operands p*q=600
/ Divide results quotient after the division of values q/p=1.5
% Modulus Return the remainder after the division of values q%p=10
% Modulus Return the remainder after the division of values q%p=10
-expr Unary Minus reverse of an expression -(10-7) is -3
~/ Division Int returns division int value (10~/7) is 1
++ Increment Increment the value by 1 ++p=21
-- Decrement Decrement 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