ePrivacy and GPDR Cookie Consent by CookieConsent.com
menu

Dart arithmetic operators

In dart language, arithmetic operators perform arithmetic on numbers.
                    +----------+--------------------------------+
                    | Operator | Description                    |
                    +----------+--------------------------------+
                    |     +    | Addition                       |
                    +----------+--------------------------------+
                    |     -    | Subtraction                    |
                    +----------+--------------------------------+
                    |     *    | Multiplication                 |
                    +----------+--------------------------------+
                    |     /    | Division                       |
                    +----------+--------------------------------+
                    |    ~/    | Divide (return always integer) |
                    +----------+--------------------------------+
                    |     %    | Modulus                        |
                    +----------+--------------------------------+
                    |    ++    | increment                      |
                    +----------+--------------------------------+
                    |    --    | decrement                      |
                    +----------+--------------------------------+


Arithmetic operations

An arithmetic operation has contained some numbers and operates on then.
Numbers can be literals.

or variables

or expression

Operator and operand

The number (or data ) is called operands.
The operation(which is defined by you to perform some actions) is called the operator.

                        +---------+----------+---------+
                        | Operand | Operator | Operand |
                        +---------+----------+---------+
                        |    50   |     +    |    60   |
                        +---------+----------+---------+


Addition

The addition operator(+) adds two numbers

Subtraction

The subtraction operator(-) subtracts two numbers

Multiplication

The multiplication operator(*) multiplies two numbers

Division

The division operator(/) divides two numbers

~/ operator

~/ operator is also used for division but the difference is this operator returns an integer value.


Modulo operator

Modulo operator (%) in dart is used for the remainder when we divide two numbers.


Increment operator

An increment operator (++) in dart is used for incrementing the number by one.


Decrement operator

The decrement operator(--) is used for decrementing the value by one.

Dart operator precedence values

+-----------------------+--------------------------------+---------------+------------+
| Description Operator  |            Operator            | Associativity | Precedence |
+-----------------------+--------------------------------+---------------+------------+
|     Unary postfix     | e., e?., e++, e--, e1[e2], e() |      None     |     16     |
+-----------------------+--------------------------------+---------------+------------+
|     Unary postfix     |  -e, !e, ˜e, ++e, --e, await e |      None     |     15     |
+-----------------------+--------------------------------+---------------+------------+
|     Multiplicative    |           *, /, ˜/, %          |      Left     |     14     |
+-----------------------+--------------------------------+---------------+------------+
|        Additive       |               +,-              |      Left     |     13     |
+-----------------------+--------------------------------+---------------+------------+
|         Shift         |            <<,>>,>>>           |      Left     |     12     |
+-----------------------+--------------------------------+---------------+------------+
|      Bitwise AND      |                &               |      Left     |     11     |
+-----------------------+--------------------------------+---------------+------------+
|      Bitwise XOR      |                ^               |      Left     |     10     |
+-----------------------+--------------------------------+---------------+------------+
|       Bitwise OR      |                |               |      Left     |      9     |
+-----------------------+--------------------------------+---------------+------------+
|       Relational      |    <, >, <=, >=, as, is, is!   |      None     |      8     |
+-----------------------+--------------------------------+---------------+------------+
|        Equality       |             ==, !=             |      None     |      7     |
+-----------------------+--------------------------------+---------------+------------+
|      Logical AND      |               &&               |      Left     |      6     |
+-----------------------+--------------------------------+---------------+------------+
|       Logical OR      |               ||               |      Left     |      5     |
+-----------------------+--------------------------------+---------------+------------+
|        if-null        |               ??               |      Left     |      4     |
+-----------------------+--------------------------------+---------------+------------+
|      Conditional      |          e1 ? e2 : e3          |     Right     |      3     |
+-----------------------+--------------------------------+---------------+------------+
|        Cascade        |               ..               |      Left     |      2     |
+-----------------------+--------------------------------+---------------+------------+
|       Assignment      | =, *=, /=, +=, -=, &=, ˆ=, etc |     Right     |      1     |
+-----------------------+--------------------------------+---------------+------------+


Comments