×

Dart Arithmetic Operators

Arithmetic Operators comprises of all the operators that are used to perform arithmetic operations such as addition, subtraction, multiplication, division, etc.

They are binary operators that work upon two operands.

Consider A = 15, B = 10 for the following table :

S. No.

Operator Name

Description

Example

1.

Addition (+)

It adds the left operand to the right operand.

A + B will return 25

2.

Subtraction (-)

It subtracts the right operand from the left operand.

A - B will return 5

3

Divide (/)

It divides the first operand by the second operand and returns the double type quotient.

A / B will return 1.5

4.

Multiplication (*)

It multiplies the one operand to another operand.

A * B will return 150

5.

Modulus (%)

It returns a remainder after dividing one operand from another.

A % B will return 5

6.

Division (~ /)

It divides the first operand by the second operand and returns integer type quotient.

A ~ / B will return 1

7.

Unary Minus (-expr)

It is used with a single operand changes the sign of it.

- ( A – B ) will return -5


Program

Consider the following code in Dart that explains the concept of arithmetic operators

void main( )

{

    int a = 157, b = 130 ;

    // addition operator ( + )

    int sum = a + b ;

    print( ' Addition of two numbers is : $sum ' ) ;

    // subtraction operator ( - )

    int diff = a - b ;

    print( ' Subtraction of two numbers is : $diff ' ) ;

    // Multiplication operator ( * )

    int prod = a * b ;

    print( ' Product of two numbers is : $prod ' ) ;

    // Division operator ( ~/ ) that returns integer type quotient

    int quo = a ~/ b ;

    print( ' Division of two numbers is : $quo ' ) ;

    // Divide operator ( / )that returns double type quotient

    double quo1 = a / b ;

    print( ' Division of two numbers is : $quo1 ' ) ;

    // Modulus operator ( % )

    int rem = a % b ;

    print( ' Remainder of two numbers is : $rem ' ) ;

    // Unary minus operator ( - )

    int res = -sum ;

    print( ' Negative of addition of two numbers is : $res ' ) ;

}

Output

 Addition of two numbers is : 287

Subtraction of two numbers is : 27

Product of two numbers is : 20410

Division of two numbers is : 1

Division of two numbers is : 1.2076923076923076

Remainder of two numbers is : 27

Negative of addition of two numbers is : -287

Remember the following points :

  1. Division Operator ( ~/ ) returns the quotient of integer type.
  2. Divide Operator ( / ) returns the quotient of double type.
  3. Unary minus ( - ) is the only arithmetic operator that works on  a single operand.

Related Topics

Dart Object-Oriented Concepts

Dart is a programming language that supports object-oriented programming. It is focused on the objects that are real-world entities and supports all the concepts of OOPS, such as objects, classes,...

4 minutes read.

Interfaces in Dart

An interface in Dart refers to the syntax or blueprint that any class must adhere to. It basically defines the array of methods available on the object. It provides the...

3 minutes read.

Soundness in Dart

What is soundness? Soundness ensures that the program never comes across any invalid state that may lead to abrupt termination of the program. As its name suggests it ensures perfect type...

4 minutes read.

Dart Built-in Data Types

A data type defines the type of value a variable can hold, such as integer, double, or string.  Dart supports two data types:  1. Built-in data types : These are the data...

1 minute read.

Dart Sets

Sets data type in Dart A set is an unordered collection of items that are unique. Dart infers that sets tale strings as values. Example, var languages = { ‘Dart’ , ‘Flutter’, ‘Python’,...

3 minutes read.

Dart Method Overriding

Before understanding method overriding, it is important to clear the concept of polymorphism. Polymorphism is derived from two Greek words 'Poly' which means many and 'morphs' which means many forms....

5 minutes read.

Dart Generators

Synchronous Generator Dart Generator is a unique function that allows us to generate price sequences. Generators return values when needed; means that the value is generated if we try to duplicate...

5 minutes read.

Dart lists data type

The most important data type in any programming language is an ordered list of elements, an array. Dart lists resemble JavaScript array lists. Example,               var...

7 minutes read.

Dart Equality and Relational Operators

Dart provides the functionality of checking the relationship between the values or values within the variables. These operators return the resultant value as Boolean, i.e., either ‘true’ or ‘false’. Some important points...

3 minutes read.

Abstract Classes in Dart

Abstract classes in Dart are those classes that only contain abstract methods  (methods that do not contain any implementation). These classes are specifically designed for the purpose of inheritance. We...

4 minutes read.

Dart Installation Guide

There are various ways of compiling and running an application created in Dart, either by compiling the Dart code to JavaScript using the Dart2js tool or by running on the...

3 minutes read.

Dart Logical Operators

Logical operators are the operators that combine two or more conditions, and accordingly return a Boolean value : true or false. Assume the value of variable A is 25 and B...

2 minutes read.

Dart - extends, with and implements Keywords

The application development in Dart programming language using the Flutter framework, regularly experience different usage of the implements, extends and with keywords. Dart has full support for inheritance that is...

5 minutes read.

Assert in DART

In any programming language, resolving error is the most unwanted and tedious task. At times it becomes very difficult to find the error in the large code. Dart offers an...

3 minutes read.

Dart Keywords

Keywords are the reserved words of a programming language, and they have a special meaning that comes defined by the language. These cannot be used as an identifier, and all...

1 minute read.

Unit Testing in Dart

Typing testing ensures that your app keeps working as you add more features or change existing functionality. Unit testing helps to confirm the behavior of a single function, method, or...

4 minutes read.

Dart Strings

Strings data type in Dart A Dart string is a sequence of characters with an encoding of UTF-16. The text associated with string data type is enclosed withing single (‘  ’)...

3 minutes read.

Dart Exception Handling

Exception Class – An exception is any runtime error that leads to abrupt termination of the program. It helps in addressing the error programmatically. It is aimed to be caught...

4 minutes read.

Dart Recursion

Recursion is one of the most important and interesting concepts in any programming language. It can be defined as a process in which a function calls itself directly or indirectly....

5 minutes read.

Lexical Scope and Closure

Lexical Scope : Lexical scope is a very important term in any programming language. It defines the scope of the variable based on the block it is contained inside. According to...

2 minutes read.