Arithmetic operators in Dart Programming


Arithmetic operators are used to perform different arithmetic operations.

These arithmetic operations mainly are −

  • Addition

  • Subtraction

  • Multiplication

  • Division

  • Modulus, etc.

Let's consider that we have two int variables named x and y, where x is storing the value 10 and y is storing the value 20.

In the below table, you can see all the arithmetic operators, with their symbol, name, what output they yield etc.

Consider the table shown below −

OperatorNameDescriptionOutput
+AdditionAddition of two or more operandsx + y = 30
-SubtractionSubtraction of the second operand from the firstx - y = -10
*MultiplicationMultiplication of two or more operandsx * y = 200
/DivisionReturns quotient after divisionx / y = 0.5
%ModulusReturns remainder after divisionx % y = 10
-exprUnary MinusReverse the sign of the expression-(x - y) = 10

Let's make use of all the above-mentioned operators in a dart program.

Example

Consider the example shown below −

 Live Demo

void main(){
   var x = 10, y = 20;
   print("x + y is: ${x + y}");
   print("x - y is: ${x - y}");
   print("x * y is: ${x * y}");
   print("x / y is: ${x / y}");
   print("x % y is: ${x % y}");
   print("- (x - y) is: ${-(x - y)}");
}

Output

x + y is: 30
x - y is: -10
x * y is: 200
x / y is: 0.5
x % y is: 10
- (x - y) is: 10

Updated on: 21-May-2021

765 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements