Dart Programming - Arithmetic Operators



Arithmetic Operators

The following table shows the arithmetic operators supported by Dart.

Sr.No Operators & Meaning
1 +

Add

2

Subtract

3 -expr

Unary minus, also known as negation (reverse the sign of the expression)

4 *

Multiply

5 /

Divide

6 ~/

Divide, returning an integer result

7 %

Get the remainder of an integer division (modulo)

8 ++

Increment

9 --

Decrement

Usage of Arithmetic Operators

Example

The following example demonstrates how you can use different operators in Dart −

void main() { 
   var num1 = 101; 
   var num2 = 2; 
   var res = 0; 
   
   res = num1+num2; 
   print("Addition: ${res}"); 
   
   res = num1-num2;
   print("Subtraction: ${res}"); 
   
   res = num1*num2; 
   print("Multiplication: ${res}"); 
   
   res = num1/num2; 
   print("Division: ${res}"); 
   
   res = num1~/num2; 
   print("Division returning Integer: ${res}"); 
   
   res = num1%num2; 
   print("Remainder: ${res}"); 
   
   num1++; 
   print("Increment: ${num1}"); 
   
   num2--; 
   print("Decrement: ${num2}"); 
}

Output

It will produce the following output −

Addition:103 
Subtraction: 99                               
Multiplication: 202               
Division: 50.5
Division returning Integer: 50                  
Remainder: 1      
Increment: 102    
Decrement: 1
dart_programming_operators.htm
Tutorix - AI Tutor
Advertisements