Arithmetic Operators

Arithmetic Operators are used to perform basic mathematical arithmetic operators like addition, subtraction, multiplication, etc. The following table lists out all the arithmetic operators in Dart programming.

OperatorSymbolExampleDescription
Addition+x+yReturns addition of x and y.
Subtractionx-yReturns the subtraction of y from x.
Multiplication*x*yReturns the multiplication of x and y.
Division/x/yReturns the quotient of the result of division of x by y.
Division~/x~/yReturns the quotient of the result of integer division of x by y.
Modulo%x%yReturns the reminder of division of x by y. Known as modular division.
Increment++x++
++x
Increments the value of x by 1.
Decrementx--
--x
Decrements the value of x by 1.

Example

In the following program, we will take values in variables x and y, and perform arithmetic operations on these values using Dart Arithmetic Operators.

main.dart

</>
Copy
void main() {
    var x = 5;
    var y = 2;
    var addition = x + y;
    var subtraction = x - y;
    var multiplication = x * y;
    var division = x / y;
    var division_1 = x / y;
    var modulus = x % y;
    print('x + y = $addition');
    print('x - y = $subtraction');
    print('x * y = $multiplication');
    print('x / y = $division');
    print('x ~/ y = $division_1');
    print('x % y = $modulus');
    print('x++ = ${++x}');
    print('y-- = ${--y}');
}

Output

x + y = 7
x - y = 3
x * y = 10
x / y = 2.5
x ~/ y = 2.5
x % y = 1
x++ = 6
y-- = 1

Arithmetic Operators Tutorials

The following tutorials cover each of the Arithmetic Operators in Dart, in detail with examples.

  • AdditionDart Tutorial on how to use Addition Operator to add two numbers.
  • SubtractionDart Tutorial on how to use Subtraction Operator to subtract a number from another.
  • MultiplicationDart Tutorial on how to use Multiplication Operator to find the product of two numbers.
  • Unary MinusDart Tutorial on how to use Unary Minus Operator to invert the sign of given number.
  • DivisionDart Tutorial on how to use Division Operator to find the quotient of division of given two numbers.
  • Division (Integer Quotient)Dart Tutorial on how to use Division Operator to find the quotient (an integer) of integer division.
  • Modulo DivisionDart Tutorial on how to use Modulo Operator to find the remainder of integer division of given two numbers.
  • IncrementDart Tutorial on how to use Increment Operator to increase the value in a variable by one.
  • DecrementDart Tutorial on how to use Decrement Operator to decrease the value in a variable by one.

Conclusion

In this Dart Tutorial, we learned about all the Arithmetic Operators in Dart programming, with examples.