Dart Operators : Arithmetic

Dart Operators : Arithmetic

ยท

2 min read

Arithmetic operators :

  • Like all programming language dart also support arithmetic operators.

  • Arithmetic operators means simple math function we can use in dart as well like Addition , Subtract and other mathematical function.

  • Here , Below I have mention all Arithmetic operators with simple definition and Example as well.

  • | Operator Symbol | Operator Name | Operator Description | | --- | --- | --- | | + | Addition | Use to add two operands | | โ€“ | Subtraction | Use to subtract two operands | | -expr | Unary Minus | It is Use to reverse the sign of the expression | | * | Multiply | Use to multiply two operands | | / | Division | Use to divide two operands | | ~/ | Division | Use two divide two operands but give output in integer |

void main() {
    var x = 5;
    var y = 2;

    var addition = x + y;
    var subtraction = x - y;
    var multiplication = x * y;
    var division = x / y;
    var division_1 = x / y;
    var modulus = x % y;

    print('x + y = $addition'); 
    print('x - y = $subtraction');
    print('x * y = $multiplication');
    print('x / y = $division');
    print('x ~/ y = $division_1');
    print('x % y = $modulus');
    print('x++ = ${++x}');
    print('y-- = ${--y}');
}

/** Output:- 

x + y = 7
x - y = 3
x * y = 10
x / y = 2.5
x ~/ y = 2.5
x % y = 1
x++ = 6
y-- = 1
**/

Did you find this article valuable?

Support Vinit Mepani (Flutter Developer) by becoming a sponsor. Any amount is appreciated!

ย