thumbnail

Arithmetic Operators in Dart

Published on 29 March 2020
Last Updated on 29 March 2020

Refer to following table to know what arithmetic operators are do in Dart.

Operator Description
- Subtracts two numbers.
+ Adds two numbers.
* Multiplies two numbers.
-expression This reverses the sign of the expression.
/ Divides while returning a double as a result of the division.
~/ Dives and returns integer result
% Gives the remainder of a division in int.

Program that demonstrates the use of Arithmetic operators in Dart

main(List<String> args) {
  // add
  print(1 + 2);
  // subtract
  print(2 - 1);
  // unary minus, changes the sign of the expression
  print(-1);
  // multiplication
  print(1 * 2);
  // division
  print(4 / 2);
  // modulo operator, returns the remainder of a division
  print(5 % 2);
  // divides returning an integer result
  print(9 ~/ 2);
}

Above program produces following output:

3
1
-1
2
2.0
1
4