×

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 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 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 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 Type inference

The task of interpreting the data types of fields, methods, local variables and most generic type arguments is handled by the static analyser. However, when not enough information is provided...

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 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 super keyword

The ' super ' keyword is used to refer to the immediate parent class object of the currently in-use child class. Using this keyword, we can invoke the superclass (...

6 minutes read.

Dart Optional Parameters

Dart functions can have optional parameters with default values. When we create a function, we can specify parameters that calling code can provide; but if the calling code chooses not...

2 minutes read.

Dart Static Members

Static Members in Dart Static members are the members of the class declared using the 'static' keyword. the static members have the following characteristics :  All the objects of the class having...

3 minutes read.

Typedef in Dart

In Dart, typedef is used to generate a function type that we can use as a type annotation for declaring variables and return types of the function type. An alias...

4 minutes 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 Classes

Dart is an object – oriented programming language that supports all the object-oriented programming concepts such as classes, objects, inheritance, data abstraction and data encapsulation. A class can be defined as...

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

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 Break and Continue

Loop statements are used to change the normal sequence of flow of the program. Dart supports two types of loop control statements: Break StatementContinue Statement Break Statement : The ‘ break ’ statement is...

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

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 Runes and Graphemes

Runes and Graphemes data types in Dart Runes and Graphemes Runes are the special string of Unicode UTF-32 bits that represent the special syntax. Unicode defines a unique numeric value for each...

2 minutes read.

Dart Standard Input & Output

Standard Input in Dart (stdin): The standard input stream reads data both synchronously and asynchronously from the keyboard.  In Dart programming language, .readLineSync( ) function is used to accept input from the...

3 minutes read.

Rust vs Dart

Rust is a system-level programming language that stands next to C ++ in terms of syntax, but offers greater speed and memory security. Dart, on the other hand, is an...

2 minutes read.