×

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

Type System in Dart

Dart language is a type safety enabled language that uses static and dynamic type checking to match the value of the variable with its data type at the compile-time. This...

4 minutes read.

Dart HTML DOM

All web pages can be viewed as objects and exist within the browser window. We can access a web page using a web browser and it needs to be connected...

3 minutes read.

Dart Objects

Apart from the built-in data types, Dart offers some other data types that have a special role to play. One of them is Objects.  Objects Objects are the foundation of the...

3 minutes read.

Dart If-else statement

In the previous section, we studied about if statements in detail. If – block is executed when the condition evaluates to true, else if the condition evaluates to false, then...

1 minute read.

Dart If statement

If statement is used to set the control on the lines of code. Using if statement, block of code is executed only if the expression in the statement returns true....

1 minute read.

Dart If-else-if statement

If - else - if statement enables to check the set of test expressions that evaluate to Boolean True or False, and based on this true or false the particular...

2 minutes read.

C++ vs Dart

Difference between C++ and Dart C++ is an object-oriented programming language developed in 1980 by Bjarne Stroustrup. It has wide real-world applications with various in-built functions and a very vast library...

1 minute read.

main function in Dart

The main( ) function is a predefined method in Dart that is also known as the entry-point of the program. The compiler begins the execution only when it comes across...

3 minutes read.

Dart Comments

Comments are the statements that are used to enhance the readability and understandability of the code. The compiler does not execute these lines. It simply ignores these comments when it scans...

2 minutes read.

Dart Anonymous Function

Dart functions are the user defined functions that are designed to perform specific task. The use case of the functions is that they can be directly called any number of...

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.

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...

2 minutes read.

Dart this Keyword

The ' this ' keyword, similar to that in Java and C#, refers to an object of the class using it. It points to the current object of the class,...

5 minutes read.

Dart Type Test Operators

Type Test Operators in Dart These operators are used to check the types of expressions at runtime. Dart is a typed language, and we often want to assert that a value...

1 minute read.

Common Collection Methods

Most of the programming languages have arrays as a way to list items together. However, Dart has a collection of data structures similar to array. These are supported by the...

3 minutes read.

Dart Queues

A queue is a user-defined collection of data. It is based on the FIFO principle ( First In First Out ) which implies that the element to be inserted first,...

3 minutes read.

Dart Inheritance

Inheritance is a promising concept of any programming language. It is a property by which a class inherits the property of another class. Moreover, the class deriving the properties of...

5 minutes read.

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.

Dart Generics

Dart Generics is similar to Dart collections, which are used to store homogeneous data. As we have discussed in Dart's features, it is a language with types being optional. By default,...

4 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.