Dart Tutorial

Dart Tutorial Single-Page Application Architecture Dart Features Dart Installation Guide Dart Basic Program Dart Syntax Dart Keywords Dart Variables Dart Comments Dart Standard Input Output Dart Important Concepts

Data Types

Built-in Data Types Numbers Strings Booleans Lists Sets Maps Runes and Graphemes Symbols Enumerations Constants Queues

Other data types

Objects Future and stream Iterable Miscellaneous types

OPERATORS

Precedence and associativity Arithmetic operators Equality and Relational operators Type Test Operators Assignment Operators Logical Operators Bitwise and Shift Operators Miscellaneous operators

Control Flow Statements

Introduction If statement If-else statement If-else-if statement Loops Switch and case Dart Break And Continue Assert In Dart

FUNCTIONS

Dart function Types of Functions Anonymous function main( ) function Lexical scope and closure Recursion Common Collection Methods

Object Oriented Concepts

Dart Object-Oriented Concepts Dart Classes Dart Constructors Dart This Keyword Dart Super Keyword Static Members Method Overriding Dart Interfaces Inheritance Dart Abstract Classes Dart Builder Classes Dart Callable Classes

Dart Type System

Dart Type System Dart Soundness Dart Type Inference

MISCELLANEOUS

Dart Isolates Dart Typedef Dart Metadata Dart Packages Dart Generics Dart Generators Dart Concurrency Dart Unit Testing Dart Html Dom Dart URIs Dart Extends, With and Implements Keywords Dart Optional Parameters Rust Vs Dart C++ vs Dart Golang Vs Dart Dart Basics Exception Handling

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.